basic working removeCommentTag mutation

This commit is contained in:
Benjamin Goering
2017-02-28 19:59:33 +08:00
parent 4ff6bce8ec
commit 30ee80b12c
5 changed files with 77 additions and 1 deletions
+17
View File
@@ -189,18 +189,31 @@ const setCommentStatus = ({loaders: {Comments}}, {id, status}) => {
/**
* Adds a tag to a Comment
* @param {String} id identifier of the comment (uuid)
* @param {String} tag name of the tag
*/
const addCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
return CommentsService.addTag(id, tag, user.id)
.then(() => CommentsService.findById( id ));
};
/**
* Removes a tag from a Comment
* @param {String} id identifier of the comment (uuid)
* @param {String} tag name of the tag
*/
const removeCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
return CommentsService.removeTag(id, tag)
.then(() => CommentsService.findById( id ));
};
module.exports = (context) => {
let mutators = {
Comment: {
create: () => Promise.reject(errors.ErrNotAuthorized),
setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized),
addCommentTag: () => Promise.reject(errors.ErrNotAuthorized),
removeCommentTag: () => Promise.reject(errors.ErrNotAuthorized),
}
};
@@ -216,5 +229,9 @@ module.exports = (context) => {
mutators.Comment.addCommentTag = (action) => addCommentTag(context, action);
}
if (context.user && context.user.can('mutation:removeCommentTag')) {
mutators.Comment.removeCommentTag = (action) => removeCommentTag(context, action);
}
return mutators;
};