From 5e0d01a6493ec68c122242cb0c4db518b2c1e4f2 Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Wed, 1 Mar 2017 14:15:31 +0800 Subject: [PATCH] lift findById out of add,removeCommentTag mutators and into root_mutation.js defs --- graph/mutators/comment.js | 6 ++---- graph/resolvers/root_mutation.js | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index c9b3b0ab0..94ffb850c 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -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) => { diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 61c4367c1..dc540b202 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -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))); }, };