mirror of
https://github.com/wassname/talk.git
synced 2026-07-15 11:26:58 +08:00
Added "assigned_by" to status changes
This commit is contained in:
+15
-5
@@ -16,6 +16,13 @@ const StatusSchema = new Schema({
|
||||
'premod',
|
||||
],
|
||||
},
|
||||
|
||||
// The User ID of the user that assigned the status.
|
||||
assigned_by: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
|
||||
created_at: Date
|
||||
}, {
|
||||
_id: false
|
||||
@@ -253,16 +260,19 @@ CommentSchema.statics.moderationQueue = (moderation, asset_id = false) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Change the status of a comment.
|
||||
* @param {String} id identifier of the comment (uuid)
|
||||
* @param {String} status the new status of the comment
|
||||
* Pushes a new status in for the user.
|
||||
* @param {String} id identifier of the comment (uuid)
|
||||
* @param {String} status the new status of the comment
|
||||
* @param {String} assigned_by the user id for the user who performed the
|
||||
* moderation action
|
||||
* @return {Promise}
|
||||
*/
|
||||
CommentSchema.statics.changeStatus = (id, status) => Comment.findOneAndUpdate({id}, {
|
||||
CommentSchema.statics.pushStatus = (id, status, assigned_by = null) => Comment.update({id}, {
|
||||
$push: {
|
||||
status: {
|
||||
type: status,
|
||||
created_at: new Date()
|
||||
created_at: new Date(),
|
||||
assigned_by
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -126,7 +126,7 @@ router.put('/:comment_id/status', authorization.needed('admin'), (req, res, next
|
||||
} = req.body;
|
||||
|
||||
Comment
|
||||
.changeStatus(req.params.comment_id, status)
|
||||
.pushStatus(req.params.comment_id, status, req.user.id)
|
||||
.then(() => {
|
||||
res.status(204).end();
|
||||
})
|
||||
|
||||
+15
-8
@@ -216,28 +216,35 @@ describe('models.Comment', () => {
|
||||
describe('#changeStatus', () => {
|
||||
|
||||
it('should change the status of a comment from no status', () => {
|
||||
return Comment.changeStatus(comments[0].id, 'rejected')
|
||||
.then(() => {
|
||||
let comment_id = comments[0].id;
|
||||
|
||||
return Comment.findById(comments[0].id);
|
||||
return Comment.findById(comment_id)
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.have.length(0);
|
||||
|
||||
return Comment.pushStatus(comment_id, 'rejected', '123');
|
||||
})
|
||||
.then(() => Comment.findById(comment_id))
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.have.length(1);
|
||||
expect(c.status[0]).to.have.property('type', 'rejected');
|
||||
expect(c.status[0]).to.have.property('assigned_by', '123');
|
||||
});
|
||||
});
|
||||
|
||||
it('should change the status of a comment from accepted', () => {
|
||||
return Comment.changeStatus(comments[1].id, 'rejected')
|
||||
.then(() => {
|
||||
|
||||
return Comment.findById(comments[1].id);
|
||||
})
|
||||
return Comment.pushStatus(comments[1].id, 'rejected', '123')
|
||||
.then(() => Comment.findById(comments[1].id))
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.have.length(2);
|
||||
expect(c.status[0]).to.have.property('type', 'accepted');
|
||||
expect(c.status[0]).to.have.property('assigned_by', null);
|
||||
|
||||
expect(c.status[1]).to.have.property('type', 'rejected');
|
||||
expect(c.status[1]).to.have.property('assigned_by', '123');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user