From fa152bda3f021af28a3741bc73d28748eaec7b1c Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 15 Feb 2017 17:48:40 -0700 Subject: [PATCH 1/2] Added count clearning for status changes --- graph/mutators/comment.js | 20 +++++++++++++++++--- services/comments.js | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index 91b2b0d01..a56612b83 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -169,9 +169,23 @@ const createPublicComment = (context, commentInput) => { * @param {String} status the new status of the comment */ -const setCommentStatus = ({comment}, {id, status}) => { - return CommentsService.setStatus(id, status) - .then(res => res); +const setCommentStatus = ({loaders: {Comments}}, {id, status}) => { + return CommentsService + .setStatus(id, status) + .then((comment) => { + + // If the loaders are present, clear the caches for these values because we + // just added a new comment, hence the counts should be updated. + if (Comments && Comments.countByAssetID && Comments.countByParentID) { + if (comment.parent_id != null) { + Comments.countByParentID.clear(comment.parent_id); + } else { + Comments.countByAssetID.clear(comment.asset_id); + } + } + + return comment; + }); }; module.exports = (context) => { diff --git a/services/comments.js b/services/comments.js index 8ec2b6038..ad9ce18db 100644 --- a/services/comments.js +++ b/services/comments.js @@ -273,7 +273,7 @@ module.exports = class CommentsService { return Promise.reject(new Error(`status ${status} is not supported`)); } - return CommentModel.update({id}, { + return CommentModel.findOneAndUpdate({id}, { $set: {status} }); } From 3be8ae39c4265347d0e8e8d89f35cbbf57a8917b Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Wed, 15 Feb 2017 17:53:13 -0700 Subject: [PATCH 2/2] Removed old TODO's --- graph/mutators/action.js | 4 ---- graph/mutators/comment.js | 4 ---- graph/mutators/user.js | 4 ---- 3 files changed, 12 deletions(-) diff --git a/graph/mutators/action.js b/graph/mutators/action.js index 3499719e1..a572a641c 100644 --- a/graph/mutators/action.js +++ b/graph/mutators/action.js @@ -45,10 +45,6 @@ const deleteAction = ({user}, {id}) => { }; module.exports = (context) => { - - // TODO: refactor to something that'll return an error in the event an attempt - // is made to mutate state while not logged in. There's got to be a better way - // to do this. if (context.user && context.user.can('mutation:createAction', 'mutation:deleteAction')) { return { Action: { diff --git a/graph/mutators/comment.js b/graph/mutators/comment.js index a56612b83..5007a3039 100644 --- a/graph/mutators/comment.js +++ b/graph/mutators/comment.js @@ -189,10 +189,6 @@ const setCommentStatus = ({loaders: {Comments}}, {id, status}) => { }; module.exports = (context) => { - - // TODO: refactor to something that'll return an error in the event an attempt - // is made to mutate state while not logged in. There's got to be a better way - // to do this. let mutators = { Comment: { create: () => Promise.reject(errors.ErrNotAuthorized), diff --git a/graph/mutators/user.js b/graph/mutators/user.js index 2c43f11be..3f87c1fb5 100644 --- a/graph/mutators/user.js +++ b/graph/mutators/user.js @@ -7,10 +7,6 @@ const setUserStatus = ({user}, {id, status}) => { }; module.exports = (context) => { - - // TODO: refactor to something that'll return an error in the event an attempt - // is made to mutate state while not logged in. There's got to be a better way - // to do this. if (context.user && context.user.can('mutation:setUserStatus')) { return { User: {