mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-04 19:21:53 +00:00
bugfix: duration and sip_status display as numbers
This commit is contained in:
@@ -15,6 +15,19 @@ const preconditions = {
|
||||
};
|
||||
const API_VERSION = config.get('services.apiVersion');
|
||||
|
||||
function coerceNumbers(callInfo) {
|
||||
if (Array.isArray(callInfo)) {
|
||||
return callInfo.map((ci) => {
|
||||
if (ci.duration) ci.duration = parseInt(ci.duration);
|
||||
if (ci.sip_status) ci.sip_status = parseInt(ci.sip_status);
|
||||
return ci;
|
||||
});
|
||||
}
|
||||
if (callInfo.duration) callInfo.duration = parseInt(callInfo.duration);
|
||||
if (callInfo.sip_status) callInfo.sip_status = parseInt(callInfo.sip_status);
|
||||
return callInfo;
|
||||
}
|
||||
|
||||
function validateTo(to) {
|
||||
if (to && typeof to === 'object') {
|
||||
switch (to.type) {
|
||||
@@ -258,7 +271,7 @@ router.get('/:sid/Calls', async(req, res) => {
|
||||
try {
|
||||
const calls = await listCalls(accountSid);
|
||||
logger.debug(`retrieved ${calls.length} calls for account sid ${accountSid}`);
|
||||
res.status(200).json(snakeCase(calls));
|
||||
res.status(200).json(coerceNumbers(snakeCase(calls)));
|
||||
} catch (err) {
|
||||
sysError(logger, res, err);
|
||||
}
|
||||
@@ -276,7 +289,7 @@ router.get('/:sid/Calls/:callSid', async(req, res) => {
|
||||
const callInfo = await retrieveCall(accountSid, callSid);
|
||||
if (callInfo) {
|
||||
logger.debug(callInfo, `retrieved call info for call sid ${callSid}`);
|
||||
res.status(200).json(snakeCase(callInfo));
|
||||
res.status(200).json(coerceNumbers(snakeCase(callInfo)));
|
||||
}
|
||||
else {
|
||||
logger.debug(`call not found for call sid ${callSid}`);
|
||||
|
||||
@@ -9,11 +9,12 @@ function snakeCase(obj) {
|
||||
}
|
||||
else if (typeof obj === 'object' && obj !== null) {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
obj[snake(key)] = obj[key];
|
||||
const value = obj[key];
|
||||
delete obj[key];
|
||||
obj[snake(key)] = value;
|
||||
});
|
||||
}
|
||||
else if (typeof obj === 'string') {
|
||||
else if (['string', 'number', 'boolean'].includes(typeof obj)) {
|
||||
obj = snake(obj);
|
||||
}
|
||||
return obj;
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@
|
||||
"config": "^3.2.4",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"jambonz-db-helpers": "^0.2.0",
|
||||
"jambonz-realtimedb-helpers": "0.1.5",
|
||||
"jambonz-db-helpers": "^0.2.2",
|
||||
"jambonz-realtimedb-helpers": "0.1.6",
|
||||
"mysql2": "^2.0.2",
|
||||
"passport": "^0.4.0",
|
||||
"passport-http-bearer": "^1.0.1",
|
||||
|
||||
Reference in New Issue
Block a user