diff --git a/routes/api/comments/index.js b/routes/api/comments/index.js index 3acca5b3e..4753b0355 100644 --- a/routes/api/comments/index.js +++ b/routes/api/comments/index.js @@ -1,10 +1,11 @@ const express = require('express'); const Comment = require('../../../models/comment'); +const Action = require('../../../models/action'); const router = express.Router(); //============================================================================== -// Routes +// Get Routes //============================================================================== router.get('/', (req, res, next) => { @@ -23,6 +24,40 @@ router.get('/:comment_id', (req, res, next) => { }); }); +//============================================================================== +// Moderation Queues Routes +//============================================================================== + +router.get('/action/:action_type', (req, res, next) => { + Action.find({'action_type': req.params.action_type, 'item_type': 'comment'}).then((actions) => { + // search all the comments that are in actions by id: item_id + // populate user by user_id + res.status(200).json(actions); + }).catch(error => { + next(error); + }); +}); + +router.get('/status/rejected', (req, res, next) => { + Comment.find({'status': 'rejected'}).then((comments) => { + res.status(200).json(comments); + }).catch(error => { + next(error); + }); +}); + +router.get('/status/pending', (req, res, next) => { + Comment.find({'status': ''}).then((comments) => { + res.status(200).json(comments); + }).catch(error => { + next(error); + }); +}); + +//============================================================================== +// Post Routes +//============================================================================== + router.post('/', (req, res, next) => { const {body, author_id, asset_id, parent_id, status} = req.body; let comment = new Comment({body, author_id, asset_id, parent_id, status}); @@ -48,14 +83,6 @@ router.post('/:comment_id', (req, res, next) => { }); }); -router.delete('/:comment_id', (req, res, next) => { - Comment.remove(req.params.comment_id).then(() => { - res.status(201).send('OK. Deleted'); - }).catch(error => { - next(error); - }); -}); - router.post('/:comment_id/status', (req, res, next) => { Comment.changeStatus(req.params.comment_id, req.body.status).then((comment) => { res.status(200).send(comment); @@ -72,4 +99,16 @@ router.post('/:comment_id/actions', (req, res, next) => { }); }); +//============================================================================== +// Delete Routes +//============================================================================== + +router.delete('/:comment_id', (req, res, next) => { + Comment.remove(req.params.comment_id).then(() => { + res.status(201).send('OK. Deleted'); + }).catch(error => { + next(error); + }); +}); + module.exports = router; diff --git a/tests/routes/api/comments/index.js b/tests/routes/api/comments/index.js index 4fbe52e94..6416d1412 100644 --- a/tests/routes/api/comments/index.js +++ b/tests/routes/api/comments/index.js @@ -66,6 +66,74 @@ describe('Get /comments', () => { }); }); +describe('Get moderation queues rejected, pending', () => { + const comments = [{ + id: 'abc', + body: 'comment 10', + asset_id: 'asset', + author_id: '123', + status: 'rejected' + }, { + id: 'def', + body: 'comment 20', + asset_id: 'asset', + author_id: '456' + }, { + id: 'hij', + body: 'comment 30', + asset_id: '456', + status: 'accepted' + }]; + + const users = [{ + id: '123', + display_name: 'Ana', + }, { + id: '456', + display_name: 'Maria', + }]; + + const actions = [{ + action_type: 'flag', + item_id: 'abc' + }, { + action_type: 'like', + item_id: 'hij' + }]; + + beforeEach(() => { + return Comment.create(comments).then(() => { + return User.create(users); + }).then(() => { + return Action.create(actions); + }); + }); + + it('should return all the rejected comments', function(done){ + chai.request(app) + .get('/api/v1/comments/status/rejected') + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body[0]).to.have.property('id'); + expect(res.body[0].id).to.equal('abc'); + done(); + }); + }); + + it('should return all the pending comments', function(done){ + chai.request(app) + .get('/api/v1/comments/status/pending') + .end(function(err, res){ + expect(err).to.be.null; + expect(res).to.have.status(200); + expect(res.body[0]).to.have.property('id'); + expect(res.body[0].id).to.equal('def'); + done(); + }); + }); +}); + describe('Post /comments', () => { const users = [{ id: '123', diff --git a/tests/routes/api/stream/index.js b/tests/routes/api/stream/index.js index 9744abb0c..b1348e88a 100644 --- a/tests/routes/api/stream/index.js +++ b/tests/routes/api/stream/index.js @@ -60,7 +60,6 @@ describe('api/stream: routes', () => { .end(function(err, res){ expect(err).to.be.null; expect(res).to.have.status(200); - if (err) {return done(err);} done(); }); });