bugfix: setting a registration hook cleared out the queue event hook, and vice-versa

This commit is contained in:
Dave Horton
2021-08-23 14:17:41 -04:00
parent ecdf9898f8
commit a06bba60e6
3 changed files with 10 additions and 32 deletions

View File

@@ -361,12 +361,14 @@ router.put('/:sid', async(req, res) => {
// create webhooks if provided // create webhooks if provided
const obj = Object.assign({}, req.body); const obj = Object.assign({}, req.body);
if (null !== obj.registration_hook) { for (const prop of ['registration_hook', 'queue_event_hook']) {
for (const prop of ['registration_hook']) { if (prop in obj) {
if (prop in obj && Object.keys(obj[prop]).length) { if (null === obj[prop]) {
obj[`${prop}_sid`] = null;
}
else if (typeof obj[prop] === 'object') {
if ('webhook_sid' in obj[prop]) { if ('webhook_sid' in obj[prop]) {
const sid = obj[prop]['webhook_sid']; const sid = obj[prop]['webhook_sid'];
delete obj[prop]['webhook_sid'];
await Webhook.update(sid, obj[prop]); await Webhook.update(sid, obj[prop]);
} }
else { else {
@@ -374,30 +376,6 @@ router.put('/:sid', async(req, res) => {
obj[`${prop}_sid`] = sid; obj[`${prop}_sid`] = sid;
} }
} }
else {
obj[`${prop}_sid`] = null;
}
delete obj[prop];
}
}
if (null !== obj.queue_event_hook) {
for (const prop of ['queue_event_hook']) {
if (prop in obj && Object.keys(obj[prop]).length) {
if ('webhook_sid' in obj[prop]) {
const sid = obj[prop]['webhook_sid'];
delete obj[prop]['webhook_sid'];
await Webhook.update(sid, obj[prop]);
}
else {
const sid = await Webhook.make(obj[prop]);
obj[`${prop}_sid`] = sid;
}
}
else {
obj[`${prop}_sid`] = null;
}
delete obj[prop];
} }
} }
@@ -409,14 +387,14 @@ router.put('/:sid', async(req, res) => {
const results = await Account.retrieve(sid); const results = await Account.retrieve(sid);
if (results.length && results[0].registration_hook_sid) orphanedRegHook = results[0].registration_hook_sid; if (results.length && results[0].registration_hook_sid) orphanedRegHook = results[0].registration_hook_sid;
obj.registration_hook_sid = null; obj.registration_hook_sid = null;
delete obj.registration_hook;
} }
if (null === obj.queue_event_hook) { if (null === obj.queue_event_hook) {
const results = await Account.retrieve(sid); const results = await Account.retrieve(sid);
if (results.length && results[0].queue_event_hook_sid) orphanedQueueHook = results[0].queue_event_hook_sid; if (results.length && results[0].queue_event_hook_sid) orphanedQueueHook = results[0].queue_event_hook_sid;
obj.queue_event_hook_sid = null; obj.queue_event_hook_sid = null;
delete obj.queue_event_hook;
} }
delete obj.registration_hook;
delete obj.queue_event_hook;
const rowsAffected = await Account.update(sid, obj); const rowsAffected = await Account.update(sid, obj);
if (rowsAffected === 0) { if (rowsAffected === 0) {

View File

@@ -56,9 +56,9 @@ services:
- ./postgres-data:/var/lib/postgresql/data - ./postgres-data:/var/lib/postgresql/data
healthcheck: healthcheck:
test: ["CMD-SHELL", "psql -h 'localhost' -U 'root' -c '\\l'"] test: ["CMD-SHELL", "psql -h 'localhost' -U 'root' -c '\\l'"]
interval: 1s interval: 3s
timeout: 3s timeout: 3s
retries: 30 retries: 60
networks: networks:
jambonz-api: jambonz-api:
ipv4_address: 172.58.0.5 ipv4_address: 172.58.0.5

0
test/postgresql/init-user-db.sh Normal file → Executable file
View File