update call now uses POST, plus bugfix #6

This commit is contained in:
Dave Horton
2021-02-19 08:52:27 -05:00
parent e633de5d4a
commit fb86875576
+11 -3
View File
@@ -60,7 +60,7 @@ function validateUpdateCall(opts) {
throw new DbErrorBadRequest('multiple options are not allowed in updateCall');
}
if (opts.call_hook && !opts.call_hook.url) throw new DbErrorBadRequest('missing call_hook.url');
if (typeof opts.call_hook === 'object' && !opts.call_hook.url) throw new DbErrorBadRequest('missing call_hook.url');
if (opts.call_status && !['completed', 'no-answer'].includes(opts.call_status)) {
throw new DbErrorBadRequest('invalid call_status');
}
@@ -131,7 +131,7 @@ async function validateCreateCall(logger, sid, req) {
});
}
if (!obj.call_hook || (obj.call_hook && !obj.call_hook.url)) {
if (!obj.call_hook || (typeof obj.call_hook === 'object' && !obj.call_hook.url)) {
throw new DbErrorBadRequest('either url or application_sid required');
}
}
@@ -417,7 +417,7 @@ router.delete('/:sid/Calls/:callSid', async(req, res) => {
/**
* update a call
*/
router.post('/:sid/Calls/:callSid', async(req, res) => {
const updateCall = async(req, res) => {
const accountSid = req.params.sid;
const callSid = req.params.callSid;
const {logger, retrieveCall} = req.app.locals;
@@ -443,6 +443,14 @@ router.post('/:sid/Calls/:callSid', async(req, res) => {
} catch (err) {
sysError(logger, res, err);
}
};
/** leaving for legacy purposes, this should have been (and now is) a PUT */
router.post('/:sid/Calls/:callSid', async(req, res) => {
await updateCall(req, res);
});
router.put('/:sid/Calls/:callSid', async(req, res) => {
await updateCall(req, res);
});
/**