mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-19 02:21:54 +00:00
ed51d8b13f
major merge of features from the hosted branch that was created temporarily during the initial launch of jambonz.org
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const router = require('express').Router();
|
|
const sysError = require('../error');
|
|
const {DbErrorBadRequest} = require('../../utils/errors');
|
|
|
|
const parseAccountSid = (url) => {
|
|
const arr = /Accounts\/([^\/]*)/.exec(url);
|
|
if (arr) return arr[1];
|
|
};
|
|
|
|
router.get('/', async(req, res) => {
|
|
const {logger, queryAlerts} = req.app.locals;
|
|
try {
|
|
logger.debug({opts: req.query}, 'GET /Alerts');
|
|
const account_sid = parseAccountSid(req.originalUrl);
|
|
const {page, count, alert_type, days, start, end} = req.query || {};
|
|
if (!page || page < 1) throw new DbErrorBadRequest('missing or invalid "page" query arg');
|
|
if (!count || count < 25 || count > 500) throw new DbErrorBadRequest('missing or invalid "count" query arg');
|
|
|
|
const data = await queryAlerts({
|
|
account_sid,
|
|
page,
|
|
page_size: count,
|
|
alert_type,
|
|
days,
|
|
start: days ? undefined : start,
|
|
end: days ? undefined : end,
|
|
});
|
|
|
|
res.status(200).json(data);
|
|
} catch (err) {
|
|
sysError(logger, res, err);
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|