From 586b703872e5bf434f4ff44676e0f0fbe7b16c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Paulillo?= Date: Wed, 4 Sep 2024 15:19:27 -0300 Subject: [PATCH] Revert "Fixes Typebot.start, fetchSessions and adds typebot composite key migration" This reverts commit a6326861da050f75be96e6fbbdbcfe5b3f78ddb2. --- .../migration.sql | 8 -------- prisma/postgresql-schema.prisma | 2 -- .../chatbot/typebot/controllers/typebot.controller.ts | 6 ++---- .../integrations/chatbot/typebot/routes/typebot.router.ts | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 prisma/postgresql-migrations/20240904141414_add_typebot_composite_key/migration.sql diff --git a/prisma/postgresql-migrations/20240904141414_add_typebot_composite_key/migration.sql b/prisma/postgresql-migrations/20240904141414_add_typebot_composite_key/migration.sql deleted file mode 100644 index 4114901c..00000000 --- a/prisma/postgresql-migrations/20240904141414_add_typebot_composite_key/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[url,typebot,instanceId]` on the table `Typebot` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateIndex -CREATE UNIQUE INDEX "Typebot_url_typebot_instanceId_key" ON "Typebot"("url", "typebot", "instanceId"); diff --git a/prisma/postgresql-schema.prisma b/prisma/postgresql-schema.prisma index 1729f6e6..931d67bd 100644 --- a/prisma/postgresql-schema.prisma +++ b/prisma/postgresql-schema.prisma @@ -311,8 +311,6 @@ model Typebot { Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) instanceId String TypebotSetting TypebotSetting[] - - @@unique([url, typebot, instanceId], name: "url_typebot_instanceId") } model TypebotSetting { diff --git a/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts b/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts index 6e86650a..b933341e 100644 --- a/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts +++ b/src/api/integrations/chatbot/typebot/controllers/typebot.controller.ts @@ -682,7 +682,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr stopBotFromMe: stopBotFromMe, keepOpen: keepOpen, prefilledVariables: prefilledVariables, - botId: findBot.id + typebotId: findBot.id, }); if (response.sessionId) { @@ -889,7 +889,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr throw new Error('Typebot not found'); } - const sessions = await this.sessionRepository.findMany({ + return await this.sessionRepository.findMany({ where: { instanceId: instanceId, remoteJid, @@ -897,8 +897,6 @@ export class TypebotController extends ChatbotController implements ChatbotContr type: 'typebot', }, }); - - return sessions; } catch (error) { this.logger.error(error); throw new Error('Error fetching sessions'); diff --git a/src/api/integrations/chatbot/typebot/routes/typebot.router.ts b/src/api/integrations/chatbot/typebot/routes/typebot.router.ts index 05e54d9a..f556f94f 100644 --- a/src/api/integrations/chatbot/typebot/routes/typebot.router.ts +++ b/src/api/integrations/chatbot/typebot/routes/typebot.router.ts @@ -113,7 +113,7 @@ export class TypebotRouter extends RouterBroker { request: req, schema: instanceSchema, ClassRef: InstanceDto, - execute: (instance) => typebotController.fetchSessions(instance, req.params.typebotId, req.query.remoteJid as string | undefined) + execute: (instance) => typebotController.fetchSessions(instance, req.params.typebotId), }); res.status(HttpStatus.OK).json(response);