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, instanceId: this.monitor.waInstances[instanceName].instanceId,
}, },
update: { update: {
...data[this.name], enabled: data[this.name]?.enabled,
events: data[this.name].events,
}, },
create: { create: {
enabled: data[this.name]?.enabled, 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({ return this.prisma.webhook.upsert({
where: { where: {
instanceId: this.monitor.waInstances[instanceName].instanceId, instanceId: this.monitor.waInstances[instanceName].instanceId,
}, },
update: { update: {
...data.webhook, enabled: data.webhook?.enabled,
events: data.webhook?.events,
url: data.webhook?.url,
webhookBase64: data.webhook.base64,
webhookByEvents: data.webhook.byEvents,
}, },
create: { create: {
enabled: data.webhook?.enabled, enabled: data.webhook?.enabled,
events: data.webhook.events, events: data.webhook?.events,
instanceId: this.monitor.waInstances[instanceName].instanceId, instanceId: this.monitor.waInstances[instanceName].instanceId,
url: data.webhook.url, url: data.webhook?.url,
webhookBase64: data.webhook.base64, webhookBase64: data.webhook.base64,
webhookByEvents: data.webhook.byEvents, webhookByEvents: data.webhook.byEvents,
}, },

View File

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