Const, service, and model updates

- Updated enum values to be uppercase
- Updated services to expose service models
- Updated models to only export the mongoose model
- Moved all mongoose static methods over to new services
- Updated tests to refelct new setup

BREAKING

- Status that were uppercased (caps) have caused issues with the
  admin pages
This commit is contained in:
Wyatt Johnson
2017-01-24 12:10:32 -07:00
parent 0994023864
commit a7e9c0c776
54 changed files with 1831 additions and 2499 deletions
+10 -9
View File
@@ -1,7 +1,8 @@
const express = require('express');
const Comment = require('../../../models/comment');
const User = require('../../../models/user');
const Action = require('../../../models/action');
const CommentsService = require('../../../services/comments');
const CommentModel = require('../../../models/comment');
const UsersService = require('../../../services/users');
const ActionsService = require('../../../services/actions');
const authorization = require('../../../middleware/authorization');
const _ = require('lodash');
@@ -10,8 +11,8 @@ const router = express.Router();
function gatherActionsAndUsers (comments) {
return Promise.all([
comments,
User.findByIdArray(_.uniq(comments.map((comment) => comment.author_id))),
Action.getActionSummaries(_.uniq([
UsersService.findByIdArray(_.uniq(comments.map((comment) => comment.author_id))),
ActionsService.getActionSummaries(_.uniq([
...comments.map((comment) => comment.id),
...comments.map((comment) => comment.author_id)
]))
@@ -30,7 +31,7 @@ router.get('/comments/pending', authorization.needed('admin'), (req, res, next)
const {asset_id} = req.query;
Comment.moderationQueue('premod', asset_id)
CommentsService.moderationQueue('PREMOD', asset_id)
.then(gatherActionsAndUsers)
.then(([comments, users, actions]) => {
res.json({comments, users, actions});
@@ -43,7 +44,7 @@ router.get('/comments/pending', authorization.needed('admin'), (req, res, next)
router.get('/comments/rejected', authorization.needed('admin'), (req, res, next) => {
const {asset_id} = req.query;
Comment.moderationQueue('rejected', asset_id)
CommentsService.moderationQueue('REJECTED', asset_id)
.then(gatherActionsAndUsers)
.then(([comments, users, actions]) => {
res.json({comments, users, actions});
@@ -64,8 +65,8 @@ router.get('/comments/flagged', authorization.needed('admin'), (req, res, next)
return query;
};
Comment.findIdsByActionType('flag')
.then(ids => assetIDWrap(Comment.find({
CommentsService.findIdsByActionType('FLAG')
.then(ids => assetIDWrap(CommentModel.find({
id: {$in: ids}
})))
.then(gatherActionsAndUsers)