Add API to set and transfer ownership

This commit is contained in:
Girish Ramakrishnan
2018-06-28 16:48:04 -07:00
parent ff5bd42bef
commit 9978dff627
6 changed files with 111 additions and 3 deletions

View File

@@ -8,7 +8,8 @@ exports = module.exports = {
remove: remove,
verifyPassword: verifyPassword,
sendInvite: sendInvite,
setGroups: setGroups
setGroups: setGroups,
transferOwnership: transferOwnership
};
var assert = require('assert'),
@@ -158,3 +159,17 @@ function setGroups(req, res, next) {
next(new HttpSuccess(204));
});
}
function transferOwnership(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.params.userId, 'string');
if (typeof req.body.ownerId !== 'string') return next(new HttpError(400, 'ownerId must be a string'));
users.transferOwnership(req.params.userId, req.body.ownerId, function (error) {
if (error && error.reason === UsersError.NOT_FOUND) return next(new HttpError(404, 'No such user'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, {}));
});
}