graph2, models: Added editComment mutation.

This commit is contained in:
2019-01-16 21:45:00 +01:00
parent 1eefa65527
commit 0e2a68a2d4
4 changed files with 117 additions and 1 deletions
+44 -1
View File
@@ -69,7 +69,50 @@ func (r *mutationResolver) AddComment(ctx context.Context, input input.CommentAd
return models.Comment{}, errors.New("Failed to add comment: " + err.Error())
}
go changes.Submit("Comment", "add", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment)
go changes.Submit("Comment", "add", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter)
return comment, nil
}
func (r *mutationResolver) EditComment(ctx context.Context, input input.CommentEditInput) (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 edit 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")
}
if input.ClearFictionalDate != nil && *input.ClearFictionalDate == true {
input.FictionalDate = &time.Time{}
}
if input.CharacterID != nil && *input.CharacterID != "" {
character, err := characters.FindID(*input.CharacterID)
if err != nil {
return models.Comment{}, errors.New("Character not found")
} else if character.Author != token.UserID {
return models.Comment{}, errors.New("That is not your character")
}
}
comment, err = comments.Edit(comment, input.Source, input.CharacterName, input.CharacterID, input.Subject, input.FictionalDate)
if err != nil {
return models.Comment{}, errors.New("Could not post comment: " + err.Error())
}
go changes.Submit("Comment", "edit", token.UserID, true, changekeys.Many(comment, chapter, models.Story{ID: chapter.StoryID}), comment, chapter)
return comment, nil
}
+3
View File
@@ -104,6 +104,9 @@ type Mutation {
"Add a comment to a chapter."
addComment(input: CommentAddInput!): Comment!
"Edit a comment in a chapter."
editComment(input: CommentEditInput!): Comment!
# Add a new log
addLog(input: LogAddInput!): Log!
+26
View File
@@ -51,4 +51,30 @@ input CommentAddInput {
"Optional subject to add to the comment, only shown in some modes."
subject: String
}
"""
Input for the editComment mutation
"""
input CommentEditInput {
"What comment to edit."
commentId: String!
"Change the markdown source."
source: String
"Change the name of the character associated with this comment."
characterName: String
"Change the character assocaited with this comment."
characterId: String
"Change the optional in-universe date of the comment."
fictionalDate: Date
"Set to clear the fictional date."
clearFictionalDate: Boolean
"Change the optional subject for the comment, only shown in some modes."
subject: String
}