Creatind endpoint to return pending users and action summaries.

This commit is contained in:
David Jay
2016-12-19 19:54:20 -05:00
parent 2324ae2d20
commit 845d274b9b
3 changed files with 36 additions and 6 deletions
+4 -2
View File
@@ -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
*/
+10
View File
@@ -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'});
};
+22 -4
View File
@@ -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;