mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
Adds service and endpoint to change displayname.
This commit is contained in:
@@ -57,6 +57,15 @@ router.post('/:user_id/status', authorization.needed('ADMIN'), (req, res, next)
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
router.post('/:user_id/displayname', authorization.needed(), (req, res, next) => {
|
||||
UsersService
|
||||
.setDisplayName(req.params.user_id, req.body.displayName)
|
||||
.then((status) => {
|
||||
res.status(201).json(status);
|
||||
})
|
||||
.catch(next);
|
||||
});
|
||||
|
||||
// /**
|
||||
// * SendEmailConfirmation sends a confirmation email to the user.
|
||||
// * @param {Request} req express request object
|
||||
|
||||
@@ -358,6 +358,24 @@ module.exports = class UsersService {
|
||||
return UserModel.update({id}, {$set: {status}});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the display name of a user.
|
||||
* @param {String} id id of a user
|
||||
* @param {String} displayName display name to set
|
||||
* @param {Function} done callback after the operation is complete
|
||||
*/
|
||||
static setDisplayName(id, displayName) {
|
||||
|
||||
// Check to see if that the displayName is not empty.
|
||||
if (displayName.length < 1) {
|
||||
|
||||
// User displayName is required! Error out here.
|
||||
return Promise.reject(new Error('display name should not be empty'));
|
||||
}
|
||||
|
||||
return UserModel.update({id}, {$set: {'displayName': displayName}});
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a user with the id.
|
||||
* @param {String} id user id (uuid)
|
||||
|
||||
Reference in New Issue
Block a user