Add route and API to set members of a group

This commit is contained in:
Girish Ramakrishnan
2016-09-29 14:44:12 -07:00
parent 79d2b0c11c
commit 8e712da2c8
5 changed files with 64 additions and 1 deletions

View File

@@ -4,7 +4,8 @@ exports = module.exports = {
get: get,
list: list,
create: create,
remove: remove
remove: remove,
update: update
};
var assert = require('assert'),
@@ -44,6 +45,20 @@ function get(req, res, next) {
});
}
function update(req, res, next) {
assert.strictEqual(typeof req.params.groupId, 'string');
if (!req.body.userIds) return next(new HttpError(404, 'missing or invalid userIds fields'));
if (!Array.isArray(req.body.userIds)) return next(new HttpError(404, 'userIds must be an array'));
groups.setMembers(req.params.groupId, req.body.userIds, function (error) {
if (error && error.reason === GroupError.NOT_FOUND) return next(new HttpError(404, 'Invalid group or user id'));
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200));
});
}
function list(req, res, next) {
groups.getAllWithMembers(function (error, result) {
if (error) return next(new HttpError(500, error));