Support username search in user listing api

This commit is contained in:
Johannes Zellner
2019-01-15 17:21:40 +01:00
parent 6d8fdb131f
commit 13fac3072d
4 changed files with 32 additions and 12 deletions

View File

@@ -91,7 +91,9 @@ function list(req, res, next) {
var perPage = typeof req.query.per_page !== 'undefined'? parseInt(req.query.per_page) : 25;
if (!perPage || perPage < 0) return next(new HttpError(400, 'per_page query param has to be a postive number'));
users.getAllPaged(page, perPage, function (error, results) {
if (req.query.search && typeof req.query.search !== 'string') return next(new HttpError(400, 'search must be a string'));
users.getAllPaged(req.query.search || null, page, perPage, function (error, results) {
if (error) return next(new HttpError(500, error));
results = results.map(users.removeRestrictedFields);