rate comment

This commit is contained in:
knst-kotov 2021-11-24 09:23:48 +03:00
parent a07ada7de0
commit 36a0770675
2 changed files with 22 additions and 0 deletions

View File

@ -55,3 +55,24 @@ async def delete_comment(_, info, id):
session.commit()
return {}
@mutation.field("rateComment")
@login_required
async def rate_comment(_, info, id, value):
auth = info.context["request"].auth
user_id = auth.user_id
with local_session() as session:
rating = session.query(CommentRating).\
filter(CommentRating.comment_id == id and CommentRating.createdBy == user_id).first()
if rating:
rating.value = value
session.commit()
return {}
CommentRating.create(
comment_id = id,
createdBy = user_id,
value = value)
return {}

View File

@ -88,6 +88,7 @@ type Mutation {
createComment(body: String!, shout: Int!, replyTo: Int): CommentResult!
updateComment(id: Int!, body: String!): CommentResult!
deleteComment(id: Int!): Result!
rateComment(id: Int!, value: Int!): Result!
}
################################### Query