addCommentTag mutation works

This commit is contained in:
Benjamin Goering
2017-02-28 19:59:32 +08:00
parent fc9c67b05c
commit 6e338290a1
16 changed files with 523 additions and 379 deletions
+14 -1
View File
@@ -187,11 +187,20 @@ const setCommentStatus = ({loaders: {Comments}}, {id, status}) => {
});
};
/**
* Adds a tag to a Comment
*/
const addCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
return CommentsService.addTag(id, tag, user.id)
.then(() => CommentsService.findById( id ));
};
module.exports = (context) => {
let mutators = {
Comment: {
create: () => Promise.reject(errors.ErrNotAuthorized),
setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized)
setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized),
addCommentTag: () => Promise.reject(errors.ErrNotAuthorized),
}
};
@@ -203,5 +212,9 @@ module.exports = (context) => {
mutators.Comment.setCommentStatus = (action) => setCommentStatus(context, action);
}
if (context.user && context.user.can('mutation:addCommentTag')) {
mutators.Comment.addCommentTag = (action) => addCommentTag(context, action);
}
return mutators;
};
+3
View File
@@ -48,6 +48,9 @@ const RootMutation = {
},
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
return wrapResponse(null)(Comment.setCommentStatus({id, status}));
},
addCommentTag(_, {id, tag}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.addCommentTag({id, tag}));
}
};
+10
View File
@@ -631,6 +631,13 @@ type SetCommentStatusResponse implements Response {
errors: [UserError]
}
# Response to addCommentTag mutation
type AddCommentTagResponse implements Response {
# An array of errors relating to the mutation that occured.
comment: Comment
errors: [UserError]
}
# All mutations for the application are defined on this object.
type RootMutation {
@@ -654,6 +661,9 @@ type RootMutation {
# Sets Comment status. Requires the `ADMIN` role.
setCommentStatus(id: ID!, status: COMMENT_STATUS!): SetCommentStatusResponse
# Add tag to comment.
addCommentTag(id: ID!, tag: String!): AddCommentTagResponse
}
################################################################################