fix: set webhook

This commit is contained in:
Davidson Gomes 2024-08-23 14:24:32 -03:00
parent ca503b49c6
commit fcdee75f39
3 changed files with 55 additions and 42 deletions

View File

@ -89,7 +89,8 @@ export class EventController {
instanceId: this.monitor.waInstances[instanceName].instanceId,
},
update: {
...data[this.name],
enabled: data[this.name]?.enabled,
events: data[this.name].events,
},
create: {
enabled: data[this.name]?.enabled,

View File

@ -30,18 +30,24 @@ export class WebhookController extends EventController implements EventControlle
}
}
console.log('data.webhook', data);
return this.prisma.webhook.upsert({
where: {
instanceId: this.monitor.waInstances[instanceName].instanceId,
},
update: {
...data.webhook,
enabled: data.webhook?.enabled,
events: data.webhook?.events,
url: data.webhook?.url,
webhookBase64: data.webhook.base64,
webhookByEvents: data.webhook.byEvents,
},
create: {
enabled: data.webhook?.enabled,
events: data.webhook.events,
events: data.webhook?.events,
instanceId: this.monitor.waInstances[instanceName].instanceId,
url: data.webhook.url,
url: data.webhook?.url,
webhookBase64: data.webhook.base64,
webhookByEvents: data.webhook.byEvents,
},

View File

@ -22,12 +22,15 @@ const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
export const webhookSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
webhook: {
type: 'object',
properties: {
enabled: { type: 'boolean' },
url: { type: 'string' },
webhookByEvents: { type: 'boolean' },
webhookBase64: { type: 'boolean' },
byEvents: { type: 'boolean' },
base64: { type: 'boolean' },
events: {
type: 'array',
minItems: 0,
@ -65,4 +68,7 @@ export const webhookSchema: JSONSchema7 = {
},
required: ['enabled', 'url'],
...isNotEmpty('enabled', 'url'),
},
},
required: ['webhook'],
};