From fb868755768118a1f0e687bc7155023fefead72e Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 19 Feb 2021 08:52:27 -0500 Subject: [PATCH] update call now uses POST, plus bugfix #6 --- lib/routes/api/accounts.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/routes/api/accounts.js b/lib/routes/api/accounts.js index e4769f2..afa8a03 100644 --- a/lib/routes/api/accounts.js +++ b/lib/routes/api/accounts.js @@ -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); }); /**