mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Move the change status of the user to a ban the user func.
This commit is contained in:
+2
-2
@@ -151,11 +151,11 @@ CommentSchema.statics.moderationQueue = function(moderation) {
|
||||
//==============================================================================
|
||||
|
||||
/**
|
||||
* Change the status of a comment.
|
||||
* Set the status of a comment.
|
||||
* @param {String} id identifier of the comment (uuid)
|
||||
* @param {String} status the new status of the comment
|
||||
*/
|
||||
CommentSchema.statics.changeStatus = function(id, status) {
|
||||
CommentSchema.statics.setStatus = function(id, status) {
|
||||
return Comment.findOneAndUpdate({'id': id}, {$set: {'status': status}}, {upsert: false, new: true});
|
||||
};
|
||||
|
||||
|
||||
+20
-3
@@ -3,6 +3,8 @@ const uuid = require('uuid');
|
||||
const bcrypt = require('bcrypt');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
const Comment = require('./comment');
|
||||
|
||||
// SALT_ROUNDS is the number of rounds that the bcrypt algorithm will run
|
||||
// through during the salting process.
|
||||
const SALT_ROUNDS = 10;
|
||||
@@ -418,9 +420,6 @@ UserService.setStatus = (id, status) => {
|
||||
return Promise.reject(new Error(`status ${status} is not supported`));
|
||||
}
|
||||
|
||||
// If we are banning the user
|
||||
// disable their account
|
||||
|
||||
return UserModel.update({
|
||||
id: id
|
||||
}, {
|
||||
@@ -430,6 +429,24 @@ UserService.setStatus = (id, status) => {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Ban a user.
|
||||
* @param {String} id id of a user
|
||||
* @param {String} comment_id id of the comment that the user was ban for.
|
||||
* @param {Function} done callback after the operation is complete
|
||||
*/
|
||||
UserService.ban = (id, comment_id) => {
|
||||
// Disable their account
|
||||
return UserService.disableUser(id)
|
||||
.then(() => {
|
||||
// Set status of the user to banned
|
||||
return UserService.setStatus(id, 'banned').then(() => {
|
||||
// Reject the comment that the user was ban for.
|
||||
return Comment.setStatus(comment_id, 'rejected');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds a user with the id.
|
||||
* @param {String} id user id (uuid)
|
||||
|
||||
Reference in New Issue
Block a user