From 3b39f13180d3cbc842ff01bb3c1fef11307bb719 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Tue, 20 Aug 2024 18:41:12 -0300 Subject: [PATCH] refactor: adjusts in module init --- .../chatbot/chatbot.controller.ts | 7 +--- .../chatbot/dify/routes/dify.router.ts | 2 +- .../chatbot/openai/routes/openai.router.ts | 2 +- .../chatbot/typebot/routes/typebot.router.ts | 2 +- .../integrations/event/event.controller.ts | 7 +--- .../event/rabbitmq/routes/rabbitmq.router.ts | 2 +- .../event/sqs/routes/sqs.router.ts | 2 +- .../event/webhook/routes/webhook.router.ts | 2 +- .../websocket/routes/websocket.router.ts | 2 +- src/api/integrations/integration.module.ts | 29 ----------------- src/api/server.module.ts | 32 +++++++++++++++++-- 11 files changed, 38 insertions(+), 51 deletions(-) delete mode 100644 src/api/integrations/integration.module.ts diff --git a/src/api/integrations/chatbot/chatbot.controller.ts b/src/api/integrations/chatbot/chatbot.controller.ts index 3cf9aef0..890caf52 100644 --- a/src/api/integrations/chatbot/chatbot.controller.ts +++ b/src/api/integrations/chatbot/chatbot.controller.ts @@ -1,11 +1,6 @@ import { InstanceDto } from '@api/dto/instance.dto'; -import { - difyController, - openaiController, - typebotController, - websocketController, -} from '@api/integrations/integration.module'; import { PrismaRepository } from '@api/repository/repository.service'; +import { difyController, openaiController, typebotController, websocketController } from '@api/server.module'; import { WAMonitoringService } from '@api/services/monitor.service'; export class ChatbotController { diff --git a/src/api/integrations/chatbot/dify/routes/dify.router.ts b/src/api/integrations/chatbot/dify/routes/dify.router.ts index 942a8cc0..017c6171 100644 --- a/src/api/integrations/chatbot/dify/routes/dify.router.ts +++ b/src/api/integrations/chatbot/dify/routes/dify.router.ts @@ -1,8 +1,8 @@ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { DifyDto, DifyIgnoreJidDto, DifySettingDto } from '@api/integrations/chatbot/dify/dto/dify.dto'; -import { difyController } from '@api/integrations/integration.module'; import { HttpStatus } from '@api/routes/index.router'; +import { difyController } from '@api/server.module'; import { difyIgnoreJidSchema, difySchema, diff --git a/src/api/integrations/chatbot/openai/routes/openai.router.ts b/src/api/integrations/chatbot/openai/routes/openai.router.ts index ce316623..15b468c4 100644 --- a/src/api/integrations/chatbot/openai/routes/openai.router.ts +++ b/src/api/integrations/chatbot/openai/routes/openai.router.ts @@ -6,8 +6,8 @@ import { OpenaiIgnoreJidDto, OpenaiSettingDto, } from '@api/integrations/chatbot/openai/dto/openai.dto'; -import { openaiController } from '@api/integrations/integration.module'; import { HttpStatus } from '@api/routes/index.router'; +import { openaiController } from '@api/server.module'; import { instanceSchema, openaiCredsSchema, diff --git a/src/api/integrations/chatbot/typebot/routes/typebot.router.ts b/src/api/integrations/chatbot/typebot/routes/typebot.router.ts index 51446d05..990cb88c 100644 --- a/src/api/integrations/chatbot/typebot/routes/typebot.router.ts +++ b/src/api/integrations/chatbot/typebot/routes/typebot.router.ts @@ -1,7 +1,7 @@ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { TypebotDto, TypebotIgnoreJidDto, TypebotSettingDto } from '@api/integrations/chatbot/typebot/dto/typebot.dto'; -import { typebotController } from '@api/integrations/integration.module'; +import { typebotController } from '@api/server.module'; import { HttpStatus } from '@api/routes/index.router'; import { instanceSchema, diff --git a/src/api/integrations/event/event.controller.ts b/src/api/integrations/event/event.controller.ts index 5f528092..d1281fda 100644 --- a/src/api/integrations/event/event.controller.ts +++ b/src/api/integrations/event/event.controller.ts @@ -1,10 +1,5 @@ -import { - rabbitmqController, - sqsController, - webhookController, - websocketController, -} from '@api/integrations/integration.module'; import { PrismaRepository } from '@api/repository/repository.service'; +import { rabbitmqController, sqsController, webhookController, websocketController } from '@api/server.module'; import { WAMonitoringService } from '@api/services/monitor.service'; import { Server } from 'http'; diff --git a/src/api/integrations/event/rabbitmq/routes/rabbitmq.router.ts b/src/api/integrations/event/rabbitmq/routes/rabbitmq.router.ts index d8b5e27c..62d4db8b 100644 --- a/src/api/integrations/event/rabbitmq/routes/rabbitmq.router.ts +++ b/src/api/integrations/event/rabbitmq/routes/rabbitmq.router.ts @@ -1,7 +1,7 @@ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { RabbitmqDto } from '@api/integrations/event/rabbitmq/dto/rabbitmq.dto'; -import { rabbitmqController } from '@api/integrations/integration.module'; +import { rabbitmqController } from '@api/server.module'; import { HttpStatus } from '@api/routes/index.router'; import { instanceSchema, rabbitmqSchema } from '@validate/validate.schema'; import { RequestHandler, Router } from 'express'; diff --git a/src/api/integrations/event/sqs/routes/sqs.router.ts b/src/api/integrations/event/sqs/routes/sqs.router.ts index 16163448..48e745f9 100644 --- a/src/api/integrations/event/sqs/routes/sqs.router.ts +++ b/src/api/integrations/event/sqs/routes/sqs.router.ts @@ -1,7 +1,7 @@ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { SqsDto } from '@api/integrations/event/sqs/dto/sqs.dto'; -import { sqsController } from '@api/integrations/integration.module'; +import { sqsController } from '@api/server.module'; import { HttpStatus } from '@api/routes/index.router'; import { instanceSchema, sqsSchema } from '@validate/validate.schema'; import { RequestHandler, Router } from 'express'; diff --git a/src/api/integrations/event/webhook/routes/webhook.router.ts b/src/api/integrations/event/webhook/routes/webhook.router.ts index e02a2750..d327ea54 100644 --- a/src/api/integrations/event/webhook/routes/webhook.router.ts +++ b/src/api/integrations/event/webhook/routes/webhook.router.ts @@ -1,6 +1,6 @@ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; -import { webhookController } from '@api/integrations/integration.module'; +import { webhookController } from '@api/server.module'; import { HttpStatus } from '@api/routes/index.router'; import { ConfigService, WaBusiness } from '@config/env.config'; import { instanceSchema, webhookSchema } from '@validate/validate.schema'; diff --git a/src/api/integrations/event/websocket/routes/websocket.router.ts b/src/api/integrations/event/websocket/routes/websocket.router.ts index d2647524..f1a48281 100644 --- a/src/api/integrations/event/websocket/routes/websocket.router.ts +++ b/src/api/integrations/event/websocket/routes/websocket.router.ts @@ -1,7 +1,7 @@ import { RouterBroker } from '@api/abstract/abstract.router'; import { InstanceDto } from '@api/dto/instance.dto'; import { WebsocketDto } from '@api/integrations/event/websocket/dto/websocket.dto'; -import { websocketController } from '@api/integrations/integration.module'; +import { websocketController } from '@api/server.module'; import { HttpStatus } from '@api/routes/index.router'; import { instanceSchema, websocketSchema } from '@validate/validate.schema'; import { RequestHandler, Router } from 'express'; diff --git a/src/api/integrations/integration.module.ts b/src/api/integrations/integration.module.ts deleted file mode 100644 index 5f124604..00000000 --- a/src/api/integrations/integration.module.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { prismaRepository, waMonitor } from '@api/server.module'; -import { configService } from '@config/env.config'; - -import { DifyController } from './chatbot/dify/controllers/dify.controller'; -import { DifyService } from './chatbot/dify/services/dify.service'; -import { OpenaiController } from './chatbot/openai/controllers/openai.controller'; -import { OpenaiService } from './chatbot/openai/services/openai.service'; -import { TypebotController } from './chatbot/typebot/controllers/typebot.controller'; -import { TypebotService } from './chatbot/typebot/services/typebot.service'; -import { RabbitmqController } from './event/rabbitmq/controllers/rabbitmq.controller'; -import { SqsController } from './event/sqs/controllers/sqs.controller'; -import { WebhookController } from './event/webhook/controllers/webhook.controller'; -import { WebsocketController } from './event/websocket/controllers/websocket.controller'; - -// events -export const websocketController = new WebsocketController(prismaRepository, waMonitor); -export const rabbitmqController = new RabbitmqController(prismaRepository, waMonitor); -export const sqsController = new SqsController(prismaRepository, waMonitor); -export const webhookController = new WebhookController(prismaRepository, waMonitor); - -// chatbots -const typebotService = new TypebotService(waMonitor, configService, prismaRepository); -export const typebotController = new TypebotController(typebotService); - -const openaiService = new OpenaiService(waMonitor, configService, prismaRepository); -export const openaiController = new OpenaiController(openaiService); - -const difyService = new DifyService(waMonitor, configService, prismaRepository); -export const difyController = new DifyController(difyService); diff --git a/src/api/server.module.ts b/src/api/server.module.ts index 1dbdd602..a8a8baba 100644 --- a/src/api/server.module.ts +++ b/src/api/server.module.ts @@ -14,7 +14,17 @@ import { TemplateController } from './controllers/template.controller'; import { ChatbotController } from './integrations/chatbot/chatbot.controller'; import { ChatwootController } from './integrations/chatbot/chatwoot/controllers/chatwoot.controller'; import { ChatwootService } from './integrations/chatbot/chatwoot/services/chatwoot.service'; +import { DifyController } from './integrations/chatbot/dify/controllers/dify.controller'; +import { DifyService } from './integrations/chatbot/dify/services/dify.service'; +import { OpenaiController } from './integrations/chatbot/openai/controllers/openai.controller'; +import { OpenaiService } from './integrations/chatbot/openai/services/openai.service'; +import { TypebotController } from './integrations/chatbot/typebot/controllers/typebot.controller'; +import { TypebotService } from './integrations/chatbot/typebot/services/typebot.service'; import { EventController } from './integrations/event/event.controller'; +import { RabbitmqController } from './integrations/event/rabbitmq/controllers/rabbitmq.controller'; +import { SqsController } from './integrations/event/sqs/controllers/sqs.controller'; +import { WebhookController } from './integrations/event/webhook/controllers/webhook.controller'; +import { WebsocketController } from './integrations/event/websocket/controllers/websocket.controller'; import { S3Controller } from './integrations/storage/s3/controllers/s3.controller'; import { S3Service } from './integrations/storage/s3/services/s3.service'; import { ProviderFiles } from './provider/sessions'; @@ -58,9 +68,6 @@ export const s3Controller = new S3Controller(s3Service); const templateService = new TemplateService(waMonitor, prismaRepository, configService); export const templateController = new TemplateController(templateService); -export const eventController = new EventController(prismaRepository, waMonitor); -export const chatbotController = new ChatbotController(prismaRepository, waMonitor); - const proxyService = new ProxyService(waMonitor); export const proxyController = new ProxyController(proxyService, waMonitor); @@ -88,4 +95,23 @@ export const chatController = new ChatController(waMonitor); export const groupController = new GroupController(waMonitor); export const labelController = new LabelController(waMonitor); +export const eventController = new EventController(prismaRepository, waMonitor); +export const chatbotController = new ChatbotController(prismaRepository, waMonitor); + +// events +export const websocketController = new WebsocketController(prismaRepository, waMonitor); +export const rabbitmqController = new RabbitmqController(prismaRepository, waMonitor); +export const sqsController = new SqsController(prismaRepository, waMonitor); +export const webhookController = new WebhookController(prismaRepository, waMonitor); + +// chatbots +const typebotService = new TypebotService(waMonitor, configService, prismaRepository); +export const typebotController = new TypebotController(typebotService); + +const openaiService = new OpenaiService(waMonitor, configService, prismaRepository); +export const openaiController = new OpenaiController(openaiService); + +const difyService = new DifyService(waMonitor, configService, prismaRepository); +export const difyController = new DifyController(difyService); + logger.info('Module - ON');