mirror of
https://github.com/wassname/talk.git
synced 2026-08-06 13:41:02 +08:00
Adds moderations queues.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user