Add route and API to set members of a group
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user