mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
major merge of features from the hosted branch that was created temporarily during the initial launch of jambonz.org
38 lines
1.1 KiB
JavaScript
38 lines
1.1 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, queryCdrs} = req.app.locals;
|
|
try {
|
|
logger.debug({opts: req.query}, 'GET /RecentCalls');
|
|
const account_sid = parseAccountSid(req.originalUrl);
|
|
const {page, count, trunk, direction, days, answered, 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 queryCdrs({
|
|
account_sid,
|
|
page,
|
|
page_size: count,
|
|
trunk,
|
|
direction,
|
|
days,
|
|
answered,
|
|
start: days ? undefined : start,
|
|
end: days ? undefined : end,
|
|
});
|
|
|
|
res.status(200).json(data);
|
|
} catch (err) {
|
|
sysError(logger, res, err);
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|