lift findById out of add,removeCommentTag mutators and into root_mutation.js defs

This commit is contained in:
Benjamin Goering
2017-03-01 14:15:31 +08:00
parent b0036ef778
commit 5e0d01a649
2 changed files with 5 additions and 6 deletions
+2 -4
View File
@@ -193,8 +193,7 @@ const setCommentStatus = ({loaders: {Comments}}, {id, status}) => {
* @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 ));
return CommentsService.addTag(id, tag, user.id);
};
/**
@@ -203,8 +202,7 @@ const addCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
* @param {String} tag name of the tag
*/
const removeCommentTag = ({user, loaders: {Comments}}, {id, tag}) => {
return CommentsService.removeTag(id, tag)
.then(() => CommentsService.findById( id ));
return CommentsService.removeTag(id, tag);
};
module.exports = (context) => {
+3 -2
View File
@@ -1,5 +1,6 @@
const {Error: {ValidationError}} = require('mongoose');
const errors = require('../../errors');
const CommentsService = require('../../services/comments');
/**
* Wraps up a promise to return an object with the resolution of the promise
@@ -50,10 +51,10 @@ const RootMutation = {
return wrapResponse(null)(Comment.setCommentStatus({id, status}));
},
addCommentTag(_, {id, tag}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.addCommentTag({id, tag}));
return wrapResponse('comment')(Comment.addCommentTag({id, tag}).then(() => CommentsService.findById(id)));
},
removeCommentTag(_, {id, tag}, {mutators: {Comment}}) {
return wrapResponse('comment')(Comment.removeCommentTag({id, tag}));
return wrapResponse('comment')(Comment.removeCommentTag({id, tag}).then(() => CommentsService.findById(id)));
},
};