Merge pull request #800 from dev-luizf/fix/manage-webhook

Fix webhook creation
This commit is contained in:
Davidson Gomes 2024-08-21 07:23:04 -03:00 committed by GitHub
commit b58ad83c12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,27 +30,24 @@ export class WebhookController extends EventController {
}
}
try {
await this.get(instanceName);
await this.get(instanceName);
return this.prisma.webhook.update({
where: {
instanceId: this.monitor.waInstances[instanceName].instanceId,
},
data,
});
} catch (err) {
return this.prisma.webhook.create({
data: {
enabled: data.enabled,
events: data.events,
instanceId: this.monitor.waInstances[instanceName].instanceId,
url: data.url,
webhookBase64: data.webhookBase64,
webhookByEvents: data.webhookByEvents,
},
});
}
return this.prisma.webhook.upsert({
where: {
instanceId: this.monitor.waInstances[instanceName].instanceId,
},
update: {
...data,
},
create: {
enabled: data.enabled,
events: data.events,
instanceId: this.monitor.waInstances[instanceName].instanceId,
url: data.url,
webhookBase64: data.webhookBase64,
webhookByEvents: data.webhookByEvents,
},
});
}
public async get(instanceName: string): Promise<wa.LocalWebHook> {