Merge active flag into update route

This commit is contained in:
Girish Ramakrishnan
2019-08-08 07:39:32 -07:00
parent d5de05b633
commit 94b4bf94c0
3 changed files with 6 additions and 33 deletions

View File

@@ -10,8 +10,7 @@ exports = module.exports = {
verifyPassword: verifyPassword,
createInvite: createInvite,
sendInvite: sendInvite,
setGroups: setGroups,
setActive: setActive
setGroups: setGroups
};
var assert = require('assert'),
@@ -70,6 +69,8 @@ function update(req, res, next) {
if (req.user.id === req.params.userId && !req.body.admin) return next(new HttpError(409, 'Cannot remove admin flag on self'));
}
if ('active' in req.body && typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean'));
users.update(req.params.userId, req.body, auditSource.fromRequest(req), function (error) {
if (error && error.reason === UsersError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error && error.reason === UsersError.ALREADY_EXISTS) return next(new HttpError(409, error.message));
@@ -193,17 +194,3 @@ function changePassword(req, res, next) {
next(new HttpSuccess(204));
});
}
function setActive(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.params.userId, 'string');
if (typeof req.body.active !== 'boolean') return next(new HttpError(400, 'active must be a boolean'));
users.setPassword(req.params.userId, req.body.active, function (error) {
if (error && error.reason === UsersError.NOT_FOUND) return next(new HttpError(404, 'User not found'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));
});
}