Add more query options for eventlog api

This commit is contained in:
Johannes Zellner
2016-05-06 16:49:17 +02:00
parent e986a67d39
commit 4c7dc5056d
4 changed files with 98 additions and 4 deletions
+15 -4
View File
@@ -15,9 +15,20 @@ function get(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'));
eventlog.getAllPaged(page, perPage, function (error, result) {
if (error) return next(new HttpError(500, error));
if (req.query.action && typeof req.query.action !== 'string') return next(new HttpError(400, 'action must be a string'));
if (req.query.search && typeof req.query.search !== 'string') return next(new HttpError(400, 'search must be a string'));
next(new HttpSuccess(200, { eventlogs: result }));
});
if (req.query.action || req.query.search) {
eventlog.getByQueryPaged(req.query.action || null, req.query.search || null, page, perPage, function (error, result) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, { eventlogs: result }));
});
} else {
eventlog.getAllPaged(page, perPage, function (error, result) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(200, { eventlogs: result }));
});
}
}