From 845d274b9b59638f907c16dc1a2cc86e605899b9 Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 19 Dec 2016 19:54:20 -0500 Subject: [PATCH] Creatind endpoint to return pending users and action summaries. --- models/action.js | 6 ++++-- models/user.js | 10 ++++++++++ routes/api/queue/index.js | 26 ++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/models/action.js b/models/action.js index 45f828226..c53a777b5 100644 --- a/models/action.js +++ b/models/action.js @@ -126,7 +126,9 @@ ActionSchema.statics.getActionSummaries = function(item_ids, current_user_id = ' item_type: { $last: '$item_type' }, - + metadata: { + $push: '$metadata' + }, current_user: { $max: { $cond: { @@ -163,7 +165,7 @@ ActionSchema.statics.getActionSummaries = function(item_ids, current_user_id = ' }; /* - * Finds all comments for a specific action. + * Finds all actions for a specific type. * @param {String} action_type type of action * @param {String} item_type type of item the action is on */ diff --git a/models/user.js b/models/user.js index 13e1c0405..f38726ca1 100644 --- a/models/user.js +++ b/models/user.js @@ -20,6 +20,8 @@ const USER_ROLES = [ // USER_STATUSES is the list of statuses that are permitted for the user status. const USER_STATUS = [ 'active', + 'pending', + 'suspended', 'banned' ]; @@ -622,3 +624,11 @@ UserService.addAction = (item_id, user_id, action_type, field, detail) => Action field, detail }); + +/** + * Returns all users with pending moderation actions. + * @return {Promise} + */ +UserService.moderationQueue = () => { + return UserModel.find({status: 'pending'}); +}; diff --git a/routes/api/queue/index.js b/routes/api/queue/index.js index 9c85fbe94..cba0a1d3a 100644 --- a/routes/api/queue/index.js +++ b/routes/api/queue/index.js @@ -12,10 +12,7 @@ const router = express.Router(); // Get Routes //============================================================================== -// Returns back all the comments that are in the moderation queue. The moderation queue is pre or post moderated, -// depending on the settings. The :moderation overwrites this settings. -// Pre-moderation: New comments are shown in the moderator queues immediately. -// Post-moderation: New comments do not appear in moderation queues unless they are flagged by other users. +// Returns back all the user actions that are in the moderation queue. router.get('/comments/pending', (req, res, next) => { const { @@ -65,4 +62,25 @@ router.get('/comments/pending', (req, res, next) => { }); }); +// Returns back all the users that are in the moderation queue. +router.get('/users/pending', (req, res, next) => { + + User.moderationQueue() + .then((users) => { + return Promise.all([ + users, + Action.getActionSummaries(users.map((user) => user.id)) + ]); + }) + .then(([users, actions]) => { + res.json({ + users, + actions + }); + }) + .catch(error => { + next(error); + }); +}); + module.exports = router;