Fix groups test and route to make name optional

This commit is contained in:
Girish Ramakrishnan
2018-06-20 09:31:50 -07:00
parent 7880a2f9c3
commit 74b1df17c0
2 changed files with 21 additions and 12 deletions

View File

@@ -55,14 +55,16 @@ function update(req, res, next) {
assert.strictEqual(typeof req.params.groupId, 'string');
assert.strictEqual(typeof req.body, 'object');
if (typeof req.body.name !== 'string') return next(new HttpError(400, 'name must be a string'));
if ('name' in req.body && typeof req.body.name !== 'string') return next(new HttpError(400, 'name must be a string'));
if (!Array.isArray(req.body.roles)) return next(new HttpError(400, 'roles must be an array'));
for (let role of req.body.roles) {
if (typeof role !== 'string') return next(new HttpError(400, 'roles must be an array of strings'));
if ('roles' in req.body) {
if (!Array.isArray(req.body.roles)) return next(new HttpError(400, 'roles must be an array'));
for (let role of req.body.roles) {
if (typeof role !== 'string') return next(new HttpError(400, 'roles must be an array of strings'));
}
}
groups.update(req.params.groupId, { name: req.body.name, roles: req.body.roles }, function (error) {
groups.update(req.params.groupId, req.body, function (error) {
if (error && error.reason === GroupsError.BAD_FIELD) return next(new HttpError(400, error.message));
if (error) return next(new HttpError(500, error));