Adds service and endpoint to change displayname.

This commit is contained in:
gaba
2017-01-31 13:51:36 -08:00
parent 80122dfdce
commit a377f61bdd
2 changed files with 27 additions and 0 deletions
+9
View File
@@ -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
+18
View File
@@ -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)