Fixes Typebot.start, fetchSessions and adds typebot composite key migration

This commit is contained in:
Júlio Paulillo 2024-09-04 12:48:17 -03:00
parent 2784b907b0
commit a6326861da
4 changed files with 15 additions and 3 deletions

View File

@ -0,0 +1,8 @@
/*
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");

View File

@ -311,6 +311,8 @@ 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 {

View File

@ -682,7 +682,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
stopBotFromMe: stopBotFromMe,
keepOpen: keepOpen,
prefilledVariables: prefilledVariables,
typebotId: findBot.id,
botId: findBot.id
});
if (response.sessionId) {
@ -889,7 +889,7 @@ export class TypebotController extends ChatbotController implements ChatbotContr
throw new Error('Typebot not found');
}
return await this.sessionRepository.findMany({
const sessions = await this.sessionRepository.findMany({
where: {
instanceId: instanceId,
remoteJid,
@ -897,6 +897,8 @@ export class TypebotController extends ChatbotController implements ChatbotContr
type: 'typebot',
},
});
return sessions;
} catch (error) {
this.logger.error(error);
throw new Error('Error fetching sessions');

View File

@ -113,7 +113,7 @@ export class TypebotRouter extends RouterBroker {
request: req,
schema: instanceSchema,
ClassRef: InstanceDto,
execute: (instance) => typebotController.fetchSessions(instance, req.params.typebotId),
execute: (instance) => typebotController.fetchSessions(instance, req.params.typebotId, req.query.remoteJid as string | undefined)
});
res.status(HttpStatus.OK).json(response);