add new /Callcount endpoint (#480)

* add new /Callcount endpoint

* update db-helpers

* update endpoint
This commit is contained in:
Sam Machin
2025-07-03 16:49:27 +01:00
committed by GitHub
parent 0d4b7e88ad
commit 9854666d4f
5 changed files with 32 additions and 9 deletions
+4 -2
View File
@@ -13,7 +13,8 @@ const {
deleteKey,
incrKey,
client: redisClient,
listConferences
listConferences,
getCallCount
} = require('@jambonz/realtimedb-helpers')({}, logger);
module.exports = {
@@ -29,5 +30,6 @@ module.exports = {
deleteKey,
redisClient,
incrKey,
listConferences
listConferences,
getCallCount
};
+19
View File
@@ -1220,4 +1220,23 @@ router.get('/:sid/Conferences', async(req, res) => {
}
});
/**
* retrieve counts of calls under an account
*/
router.get('/:sid/CallCount', async(req, res) => {
const {logger, getCallCount} = req.app.locals;
try {
const accountSid = parseAccountSid(req);
await validateRequest(req, accountSid);
const count = await getCallCount(accountSid);
count.outbound = Number(count.outbound);
count.inbound = Number(count.inbound);
logger.debug(`retrieved, outbound: ${count.outbound}, inbound: ${count.inbound}, for account sid ${accountSid}`);
res.status(200).json(count);
updateLastUsed(logger, accountSid, req).catch((err) => {});
} catch (err) {
sysError(logger, res, err);
}
});
module.exports = router;