Added count clearning for status changes

This commit is contained in:
Wyatt Johnson
2017-02-15 17:48:40 -07:00
parent 57d4f9d757
commit fa152bda3f
2 changed files with 18 additions and 4 deletions
+17 -3
View File
@@ -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) => {
+1 -1
View File
@@ -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}
});
}