diff --git a/models/comment.js b/models/comment.js index 3f99bcb6a..a80e353f0 100644 --- a/models/comment.js +++ b/models/comment.js @@ -86,9 +86,13 @@ CommentSchema.statics.findAcceptedAndNewByAssetId = function(asset_id) { * @param {String} action_type the type of action that was performed on the comment */ CommentSchema.statics.findByActionType = function(action_type) { - return Action.findCommentsIdByActionType(action_type, 'comment').then((actions) => { - return Comment.find({'id': {'$in': actions.map(function(a){return a.item_id;})}}); - }); + return Action + .findCommentsIdByActionType(action_type, 'comment') + .then((actions) => { + return Comment.find({'id': {'$in': actions.map(function(a){ + return a.item_id;})} + }); + }); }; /** @@ -97,9 +101,18 @@ CommentSchema.statics.findByActionType = function(action_type) { * @param {String} status the status of the comment to search for */ CommentSchema.statics.findByStatusByActionType = function(status, action_type) { - return Action.findCommentsIdByActionType(action_type, 'comment').then((actions) => { - return Comment.find({'status': status, 'id': {'$in': actions.map(function(a){return a.item_id;})}}); - }); + return Action + .findCommentsIdByActionType(action_type, 'comment') + .then((actions) => { + + return Comment.find({ + 'status': status, + 'id': {'$in': actions.map(a => { + return a.item_id;} + )} + }); + + }); }; /** diff --git a/models/setting.js b/models/setting.js index 15c457307..7d1f4b367 100644 --- a/models/setting.js +++ b/models/setting.js @@ -12,7 +12,7 @@ const SettingSchema = new Schema({ }); /** - * gets the entire settings record and sends it back + * Gets the entire settings record and sends it back * @return {Promise} settings the whole settings record */ SettingSchema.statics.getSettings = function () { @@ -20,7 +20,7 @@ SettingSchema.statics.getSettings = function () { }; /** - * gets the moderation settings and sends it back + * Gets the moderation settings and sends it back * @return {Promise} moderation the settings for how to moderate comments */ SettingSchema.statics.getModerationSetting = function () { @@ -28,12 +28,13 @@ SettingSchema.statics.getModerationSetting = function () { }; /** - * this will update the settings object with whatever you pass in + * This will update the settings object with whatever you pass in * @param {object} setting a hash of whatever settings you want to update * @return {Promise} settings Promise that resolves to the entire (updated) settings object. */ SettingSchema.statics.updateSettings = function (setting) { - // there should only ever be one record unless something has gone wrong. + // There should only ever be one record unless something has gone wrong. + // In the future we may have multiple records for custom settings for objects/users. return this.findOneAndUpdate({id: '1'}, {$set: setting}, {new: true}); }; diff --git a/models/user.js b/models/user.js index 0370a7e33..ac642c910 100644 --- a/models/user.js +++ b/models/user.js @@ -100,20 +100,22 @@ UserSchema.statics.findLocalUser = function(email, password) { UserSchema.statics.mergeUsers = function(dstUserID, srcUserID) { let srcUser, dstUser; - return Promise.all([ - User.findOne({id: dstUserID}).exec(), - User.findOne({id: srcUserID}).exec() - ]).then((users) => { - dstUser = users[0]; - srcUser = users[1]; + return Promise + .all([ + User.findOne({id: dstUserID}).exec(), + User.findOne({id: srcUserID}).exec() + ]) + .then((users) => { + dstUser = users[0]; + srcUser = users[1]; - srcUser.profiles.forEach((profile) => { - dstUser.profiles.push(profile); - }); + srcUser.profiles.forEach((profile) => { + dstUser.profiles.push(profile); + }); - return srcUser.remove(); - }) - .then(() => dstUser.save()); + return srcUser.remove(); + }) + .then(() => dstUser.save()); }; /** @@ -123,33 +125,34 @@ UserSchema.statics.mergeUsers = function(dstUserID, srcUserID) { * @param {Function} done [description] */ UserSchema.statics.findOrCreateExternalUser = function(profile) { - return User.findOne({ - profiles: { - $elemMatch: { - id: profile.id, - provider: profile.provider - } - } - }) - .then((user) => { - if (user) { - return user; - } - - // The user was not found, lets create them! - user = new User({ - displayName: profile.displayName, - roles: [], - profiles: [ - { + return User + .findOne({ + profiles: { + $elemMatch: { id: profile.id, provider: profile.provider } - ] - }); + } + }) + .then((user) => { + if (user) { + return user; + } - return user.save(); - }); + // The user was not found, lets create them! + user = new User({ + displayName: profile.displayName, + roles: [], + profiles: [ + { + id: profile.id, + provider: profile.provider + } + ] + }); + + return user.save(); + }); }; UserSchema.statics.changePassword = function(id, password) { diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index e8a995089..5126bf93c 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -13,9 +13,7 @@ router.get('/', (req, res, next) => { Comment.find({}).then((comments) => { res.status(200).json(comments); }) - .catch(error => { - next(error); - }); + .catch(next); }); router.get('/:comment_id', (req, res, next) => { @@ -24,9 +22,7 @@ router.get('/:comment_id', (req, res, next) => { .then(comment => { res.status(200).json(comment); }) - .catch(error => { - next(error); - }); + .catch(next); }); //============================================================================== @@ -40,9 +36,7 @@ router.get('/action/:action_type', (req, res, next) => { .then((comments) => { res.status(200).json(comments); }) - .catch(error => { - next(error); - }); + .catch(next); }); // Get all the comments that were rejected. @@ -52,9 +46,7 @@ router.get('/status/rejected', (req, res, next) => { .then(comments => { res.status(200).json(comments); }) - .catch(error => { - next(error); - }); + .catch(next); }); // Returns back all the comments that are in the moderation queue. The moderation queue is pre or post moderated, @@ -76,9 +68,7 @@ router.get('/status/pending', (req, res, next) => { res.status(200).json(comments); }); }) - .catch(error => { - next(error); - }); + .catch(next); }); //==============================================================================