remotes/1693045480750635534/spooky-22
Aevann1 2021-07-26 22:01:39 +02:00
parent daa435bac6
commit d2661bd222
1 changed files with 4 additions and 7 deletions

View File

@ -103,6 +103,7 @@ def api_vote_post(post_id, new, v):
g.db.add(post.author)
existing.vote_type = new
g.db.add(existing)
g.db.commit()
else:
if new != 0:
post.author.dramacoins += 1
@ -112,10 +113,8 @@ def api_vote_post(post_id, new, v):
submission_id=base36decode(post_id),
app_id=v.client.application.id if v.client else None
)
g.db.add(vote)
g.db.flush()
g.db.commit()
post.upvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=1).count()
post.downvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=-1).count()
@ -152,6 +151,7 @@ def api_vote_comment(comment_id, new, v):
g.db.add(comment.author)
existing.vote_type = new
g.db.add(existing)
g.db.commit()
else:
if new != 0:
comment.author.dramacoins += 1
@ -163,10 +163,7 @@ def api_vote_comment(comment_id, new, v):
)
g.db.add(vote)
try:
g.db.flush()
except:
return jsonify({"error":"Vote already exists."}), 422
g.db.commit()
comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count()
comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count()