Add ability to filter users by state
This commit is contained in:
@@ -103,12 +103,14 @@ async function list(req, res, next) {
|
||||
const page = typeof req.query.page !== 'undefined' ? parseInt(req.query.page) : 1;
|
||||
if (!page || page < 0) return next(new HttpError(400, 'page query param has to be a postive number'));
|
||||
|
||||
const perPage = typeof req.query.per_page !== 'undefined'? parseInt(req.query.per_page) : 25;
|
||||
const 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'));
|
||||
|
||||
if (req.query.search && typeof req.query.search !== 'string') return next(new HttpError(400, 'search must be a string'));
|
||||
|
||||
let [error, results] = await safe(users.listPaged(req.query.search || null, page, perPage));
|
||||
const active = typeof req.query.active !== 'undefined' ? ((req.query.active === '1' || req.query.active === 'true') ? true : false) : null;
|
||||
|
||||
let [error, results] = await safe(users.listPaged(req.query.search || null, active, page, perPage));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
results = results.map(users.removeRestrictedFields);
|
||||
|
||||
Reference in New Issue
Block a user