From 92a0d8ccc9813629ed0a0e07c05f41adab4bef76 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 14 Jun 2024 09:25:18 -0300 Subject: [PATCH] feat: update API routes and services for better cache handling Modified instance.router.ts to change HTTP method from PUT to POST for 'restart' route. Updated whatsapp.baileys.service.ts to correct cache configuration logic, ensuring proper usage of cached group metadata. Removed obsolete Typebot-related schema definitions from instance.schema.ts for cleaner validation. These changes improve API functionality and maintainability. --- src/api/routes/instance.router.ts | 2 +- .../channels/whatsapp.baileys.service.ts | 26 +++++++------------ src/validate/instance.schema.ts | 8 ------ 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/api/routes/instance.router.ts b/src/api/routes/instance.router.ts index ca74f807..21f8ef6b 100644 --- a/src/api/routes/instance.router.ts +++ b/src/api/routes/instance.router.ts @@ -21,7 +21,7 @@ export class InstanceRouter extends RouterBroker { return res.status(HttpStatus.CREATED).json(response); }) - .put(this.routerPath('restart'), ...guards, async (req, res) => { + .post(this.routerPath('restart'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: null, diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index d280d008..388dd6e6 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -1826,10 +1826,8 @@ export class BaileysStartupService extends ChannelStartupService { { ...option, useCachedGroupMetadata: - !this.configService.get('CACHE').REDIS.ENABLED && - !this.configService.get('CACHE').LOCAL.ENABLED - ? false - : true, + !!this.configService.get('CACHE').REDIS.ENABLED && + !!this.configService.get('CACHE').LOCAL.ENABLED, } as unknown as MiscMessageGenerationOptions, ); } @@ -1845,10 +1843,8 @@ export class BaileysStartupService extends ChannelStartupService { { ...option, useCachedGroupMetadata: - !this.configService.get('CACHE').REDIS.ENABLED && - !this.configService.get('CACHE').LOCAL.ENABLED - ? false - : true, + !!this.configService.get('CACHE').REDIS.ENABLED && + !!this.configService.get('CACHE').LOCAL.ENABLED, } as unknown as MiscMessageGenerationOptions, ); } @@ -1866,10 +1862,8 @@ export class BaileysStartupService extends ChannelStartupService { { ...option, useCachedGroupMetadata: - !this.configService.get('CACHE').REDIS.ENABLED && - !this.configService.get('CACHE').LOCAL.ENABLED - ? false - : true, + !!this.configService.get('CACHE').REDIS.ENABLED && + !!this.configService.get('CACHE').LOCAL.ENABLED, } as unknown as MiscMessageGenerationOptions, ); } @@ -1892,10 +1886,8 @@ export class BaileysStartupService extends ChannelStartupService { { ...option, useCachedGroupMetadata: - !this.configService.get('CACHE').REDIS.ENABLED && - !this.configService.get('CACHE').LOCAL.ENABLED - ? false - : true, + !!this.configService.get('CACHE').REDIS.ENABLED && + !!this.configService.get('CACHE').LOCAL.ENABLED, } as unknown as MiscMessageGenerationOptions, ); })(); @@ -2003,6 +1995,8 @@ export class BaileysStartupService extends ChannelStartupService { public async setPresence(data: SetPresenceDto) { try { await this.client.sendPresenceUpdate(data.presence); + + return { presence: data.presence }; } catch (error) { this.logger.error(error); throw new BadRequestException(error.toString()); diff --git a/src/validate/instance.schema.ts b/src/validate/instance.schema.ts index 2fdcc4c4..ee306164 100644 --- a/src/validate/instance.schema.ts +++ b/src/validate/instance.schema.ts @@ -171,14 +171,6 @@ export const instanceSchema: JSONSchema7 = { chatwootMergeBrazilContacts: { type: 'boolean' }, chatwootImportMessages: { type: 'boolean' }, chatwootDaysLimitImportMessages: { type: 'number' }, - // Typebot - typebotUrl: { type: 'string' }, - typebot: { type: 'boolean' }, - typebotExpire: { type: 'number' }, - typebotKeywordFinish: { type: 'string' }, - typebotDelayMessage: { type: 'number' }, - typebotUnknownMessage: { type: 'string' }, - typebotListeningFromMe: { type: 'boolean' }, }, ...isNotEmpty('instanceName'), };