From b0036ef77842247c8bd2f75174547a642c6afcd6 Mon Sep 17 00:00:00 2001 From: Benjamin Goering Date: Wed, 1 Mar 2017 14:09:03 +0800 Subject: [PATCH] Remove findById in error conditions of CommentsService@addTag,removeTag --- services/comments.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/services/comments.js b/services/comments.js index 85cc03167..75b53873a 100644 --- a/services/comments.js +++ b/services/comments.js @@ -73,14 +73,8 @@ module.exports = class CommentsService { switch (nModified) { case 0: - // either the tag was already there, or the comment doesn't exist with that id... - return this.findById(id) - .then(result => { - if ( ! result) { - throw new Error(`Can't add tag to comment. There is no comment with id ${id}`); - } - throw new Error(`Can't add tag ${name} to comment. Comment already has that tag.`); - }); + // either the tag was already there, or the comment doesn't exist with that id... + throw new Error('Could not add tag to comment. Either the comment doesn\'t exist or the tag is already present.'); case 1: // tag added @@ -108,15 +102,7 @@ module.exports = class CommentsService { .then(({nModified}) => { switch (nModified) { case 0: - - // either the tag was already there, or the comment doesn't exist with that id... - return this.findById(id) - .then(result => { - if ( ! result) { - throw new Error(`Can't remove tag from comment. There is no comment with id ${id}`); - } - throw new Error(`Can't remove tag ${name} from comment. Comment doesn't have that tag.`); - }); + throw new Error('Could not remove tag from comment. Either the comment doesn\'t exist or the tag is not present'); case 1: // tag removed