From cdf822291f6c50d4165f0e53ac53ad5e6ff6bf33 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Mon, 29 Jan 2024 11:35:30 -0300 Subject: [PATCH] lint --- src/config/env.config.ts | 2 +- src/whatsapp/models/message.model.ts | 2 +- src/whatsapp/services/chatwoot.service.ts | 57 +++++++++++------------ 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/config/env.config.ts b/src/config/env.config.ts index fcc00c7c..fec66eff 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -149,7 +149,7 @@ export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook }; export type ConfigSessionPhone = { CLIENT: string; NAME: string }; export type QrCode = { LIMIT: number; COLOR: string }; export type Typebot = { API_VERSION: string; KEEP_OPEN: boolean }; -export type ChatWoot = { MESSAGE_DELETE: boolean }; +export type ChatWoot = { MESSAGE_DELETE: boolean }; export type CacheConf = { REDIS: CacheConfRedis; LOCAL: CacheConfLocal }; export type Production = boolean; diff --git a/src/whatsapp/models/message.model.ts b/src/whatsapp/models/message.model.ts index 8388799c..326f982b 100644 --- a/src/whatsapp/models/message.model.ts +++ b/src/whatsapp/models/message.model.ts @@ -45,7 +45,7 @@ const messageSchema = new Schema({ participant: { type: String }, messageType: { type: String }, message: { type: Object }, - source: { type: String, minlength: 3, enum: ['android', 'web', 'ios','unknown','desktop' ] }, + source: { type: String, minlength: 3, enum: ['android', 'web', 'ios', 'unknown', 'desktop'] }, messageTimestamp: { type: Number, required: true }, owner: { type: String, required: true, minlength: 1 }, chatwoot: { diff --git a/src/whatsapp/services/chatwoot.service.ts b/src/whatsapp/services/chatwoot.service.ts index d0c0ac85..afa6e874 100644 --- a/src/whatsapp/services/chatwoot.service.ts +++ b/src/whatsapp/services/chatwoot.service.ts @@ -7,7 +7,7 @@ import Jimp from 'jimp'; import mimeTypes from 'mime-types'; import path from 'path'; -import { ConfigService, HttpServer, ChatWoot} from '../../config/env.config'; +import { ChatWoot, ConfigService, HttpServer } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; import i18next from '../../utils/i18n'; import { ICache } from '../abstract/abstract.cache'; @@ -1895,37 +1895,36 @@ export class ChatwootService { } if (event === Events.MESSAGES_DELETE) { - - const chatwootDelete = this.configService.get('CHATWOOT').MESSAGE_DELETE - if (chatwootDelete === true) { - this.logger.verbose('deleting message from instance: ' + instance.instanceName); + const chatwootDelete = this.configService.get('CHATWOOT').MESSAGE_DELETE; + if (chatwootDelete === true) { + this.logger.verbose('deleting message from instance: ' + instance.instanceName); - if (!body?.key?.id) { - this.logger.warn('message id not found'); - return; - } + if (!body?.key?.id) { + this.logger.warn('message id not found'); + return; + } - const message = await this.getMessageByKeyId(instance, body.key.id); - if (message?.chatwoot?.messageId && message?.chatwoot?.conversationId) { - this.logger.verbose('deleting message in repository. Message id: ' + body.key.id); - this.repository.message.delete({ - where: { - key: { - id: body.key.id, - }, - owner: instance.instanceName, - }, - }); + const message = await this.getMessageByKeyId(instance, body.key.id); + if (message?.chatwoot?.messageId && message?.chatwoot?.conversationId) { + this.logger.verbose('deleting message in repository. Message id: ' + body.key.id); + this.repository.message.delete({ + where: { + key: { + id: body.key.id, + }, + owner: instance.instanceName, + }, + }); - this.logger.verbose('deleting message in chatwoot. Message id: ' + body.key.id); - return await client.messages.delete({ - accountId: this.provider.account_id, - conversationId: message.chatwoot.conversationId, - messageId: message.chatwoot.messageId, - }); - } - } - } + this.logger.verbose('deleting message in chatwoot. Message id: ' + body.key.id); + return await client.messages.delete({ + accountId: this.provider.account_id, + conversationId: message.chatwoot.conversationId, + messageId: message.chatwoot.messageId, + }); + } + } + } if (event === 'messages.read') { this.logger.verbose('read message from instance: ' + instance.instanceName);