fix: set events

This commit is contained in:
Davidson Gomes 2024-08-23 14:56:33 -03:00
parent d7b3230db9
commit 0fca8c0746
4 changed files with 33 additions and 85 deletions

View File

@ -80,7 +80,7 @@ export class EventController {
data[this.name].events = [];
} else {
if (0 === data[this.name].events.length) {
data[this.name].events = this.events;
data[this.name].events = EventController.events;
}
}
@ -122,7 +122,7 @@ export class EventController {
return data;
}
public readonly events = [
public static readonly events = [
'APPLICATION_STARTUP',
'QRCODE_UPDATED',
'MESSAGES_SET',

View File

@ -1,29 +1,26 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
export * from '@api/integrations/event/webhook/webhook.schema';
import { EventController } from './event.controller';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};
export * from '@api/integrations/event/webhook/webhook.schema';
export const eventSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
websocket: {
$ref: '#/$defs/event',
},
rabbitmq: {
$ref: '#/$defs/event',
},
sqs: {
$ref: '#/$defs/event',
},
},
$defs: {
event: {
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
@ -32,36 +29,11 @@ export const eventSchema: JSONSchema7 = {
minItems: 0,
items: {
type: 'string',
enum: [
'APPLICATION_STARTUP',
'QRCODE_UPDATED',
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_EDITED',
'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
'PRESENCE_UPDATE',
'CHATS_SET',
'CHATS_UPSERT',
'CHATS_UPDATE',
'CHATS_DELETE',
'GROUPS_UPSERT',
'GROUP_UPDATE',
'GROUP_PARTICIPANTS_UPDATE',
'CONNECTION_UPDATE',
'LABELS_EDIT',
'LABELS_ASSOCIATION',
'CALL',
'TYPEBOT_START',
'TYPEBOT_CHANGE_STATUS',
],
enum: EventController.events,
},
},
},
required: ['enabled'],
...isNotEmpty('enabled'),
},
},
};

View File

@ -26,7 +26,7 @@ export class WebhookController extends EventController implements EventControlle
data.webhook.events = [];
} else {
if (0 === data.webhook.events.length) {
data.webhook.events = this.events;
data.webhook.events = EventController.events;
}
}

View File

@ -1,6 +1,8 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { EventController } from '../event.controller';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
@ -36,33 +38,7 @@ export const webhookSchema: JSONSchema7 = {
minItems: 0,
items: {
type: 'string',
enum: [
'APPLICATION_STARTUP',
'QRCODE_UPDATED',
'MESSAGES_SET',
'MESSAGES_UPSERT',
'MESSAGES_EDITED',
'MESSAGES_UPDATE',
'MESSAGES_DELETE',
'SEND_MESSAGE',
'CONTACTS_SET',
'CONTACTS_UPSERT',
'CONTACTS_UPDATE',
'PRESENCE_UPDATE',
'CHATS_SET',
'CHATS_UPSERT',
'CHATS_UPDATE',
'CHATS_DELETE',
'GROUPS_UPSERT',
'GROUP_UPDATE',
'GROUP_PARTICIPANTS_UPDATE',
'CONNECTION_UPDATE',
'LABELS_EDIT',
'LABELS_ASSOCIATION',
'CALL',
'TYPEBOT_START',
'TYPEBOT_CHANGE_STATUS',
],
enum: EventController.events,
},
},
},