bugfix: queue event hook was getting set to register hook

This commit is contained in:
Dave Horton
2021-08-25 19:09:00 -04:00
parent 43393a2e4a
commit 9525cf5a36
2 changed files with 8 additions and 5 deletions
+1 -1
View File
@@ -68,7 +68,7 @@ function transmogrifyResults(results) {
/* queue event hook */
if (row.qh && Object.keys(row.qh).length && row.qh.url !== null) {
Object.assign(obj, {queue_event_hook: row.rh});
Object.assign(obj, {queue_event_hook: row.qh});
delete obj.queue_event_hook.webhook_sid;
}
else obj.queue_event_hook = null;
+7 -4
View File
@@ -253,6 +253,9 @@ async function validateAdd(req) {
if (req.body.registration_hook && typeof req.body.registration_hook !== 'object') {
throw new DbErrorBadRequest('\'registration_hook\' must be an object when adding an account');
}
if (req.body.queue_event_hook && typeof req.body.queue_event_hook !== 'object') {
throw new DbErrorBadRequest('\'queue_event_hook\' must be an object when adding an account');
}
}
async function validateUpdate(req, sid) {
if (req.user.hasAccountAuth && req.user.account_sid !== sid) {
@@ -292,11 +295,11 @@ router.post('/', async(req, res) => {
// create webhooks if provided
const obj = {...req.body, webhook_secret: secret};
for (const prop of ['registration_hook']) {
if (obj[prop]) {
for (const prop of ['registration_hook', 'queue_event_hook']) {
if (obj[prop] && obj[prop].url && obj[prop].url.length > 0) {
obj[`${prop}_sid`] = await Webhook.make(obj[prop]);
delete obj[prop];
}
delete obj[prop];
}
logger.debug(`Attempting to add account ${JSON.stringify(obj)}`);
@@ -363,7 +366,7 @@ router.put('/:sid', async(req, res) => {
const obj = Object.assign({}, req.body);
for (const prop of ['registration_hook', 'queue_event_hook']) {
if (prop in obj) {
if (null === obj[prop]) {
if (null === obj[prop] || !obj[prop].url || 0 === obj[prop].url.length) {
obj[`${prop}_sid`] = null;
}
else if (typeof obj[prop] === 'object') {