graph2, models: Added removeComment mutation.
the build was successful

This commit is contained in:
2019-01-16 22:03:28 +01:00
parent dfa9fb4025
commit 22592439da
3 changed files with 39 additions and 0 deletions
+28
View File
@@ -116,3 +116,31 @@ func (r *mutationResolver) EditComment(ctx context.Context, input input.CommentE
return comment, nil
}
func (r *mutationResolver) RemoveComment(ctx context.Context, input input.CommentRemoveInput) (models.Comment, error) {
comment, err := comments.Find(input.CommentID)
if err != nil {
return models.Comment{}, errors.New("Comment not found")
}
token := auth.TokenFromContext(ctx)
if !token.PermittedUser(comment.Author, "member", "story.edit") {
return models.Comment{}, errors.New("You cannot remove this comment")
}
chapter, err := chapters.FindID(comment.ChapterID)
if err != nil {
return models.Comment{}, errors.New("Comment's chapter not found")
}
if !chapter.CanComment() {
return models.Comment{}, errors.New("Comments are disabled or locked")
}
err = comments.Remove(comment)
if err != nil {
return models.Comment{}, errors.New("Failed to remove comment: " + err.Error())
}
return comment, nil
}
+3
View File
@@ -107,6 +107,9 @@ type Mutation {
"Edit a comment in a chapter."
editComment(input: CommentEditInput!): Comment!
"Remove a comemnt in a chapter."
removeComment(input: CommentRemoveInput!): Comment!
# Add a new log
addLog(input: LogAddInput!): Log!
+8
View File
@@ -77,4 +77,12 @@ input CommentEditInput {
"Change the optional subject for the comment, only shown in some modes."
subject: String
}
"""
Input for the removeComment mutation
"""
input CommentRemoveInput {
"What comment to edit."
commentId: String!
}