From ca3dadfb3547034b8531161233d135f0801fa6dc Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 12 Jul 2024 13:01:17 -0300 Subject: [PATCH] Fix: Resolve issue with template association in Instance model The Issue: The Instance model in the postgresql-schema.prisma file previously had a Template field that was a single Template object, but this caused issues with the association of multiple templates to a single instance. The Change: This commit resolves the issue by changing the Template field to an array of Template objects. This allows for multiple templates to be associated with a single instance. The Impact: This change allows for more flexible use of templates in the system and resolves a previous limitation in the association of templates to instances. Affected Files: - prisma/postgresql-schema.prisma - src/api/services/template.service.ts Note: The migration folder added in the untracked files section is a result of the Prisma schema change and can be safely ignored in this commit message. --- .../20240712155950_adjusts_in_templates_table/migration.sql | 2 ++ prisma/postgresql-schema.prisma | 4 ++-- src/api/services/template.service.ts | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 prisma/migrations/20240712155950_adjusts_in_templates_table/migration.sql diff --git a/prisma/migrations/20240712155950_adjusts_in_templates_table/migration.sql b/prisma/migrations/20240712155950_adjusts_in_templates_table/migration.sql new file mode 100644 index 00000000..2ec61dac --- /dev/null +++ b/prisma/migrations/20240712155950_adjusts_in_templates_table/migration.sql @@ -0,0 +1,2 @@ +-- DropIndex +DROP INDEX "Template_instanceId_key"; diff --git a/prisma/postgresql-schema.prisma b/prisma/postgresql-schema.prisma index 3cffa90c..6c0ee0d4 100644 --- a/prisma/postgresql-schema.prisma +++ b/prisma/postgresql-schema.prisma @@ -75,7 +75,7 @@ model Instance { MessageUpdate MessageUpdate[] TypebotSession TypebotSession[] TypebotSetting TypebotSetting? - Template Template? + Template Template[] } model Session { @@ -315,5 +315,5 @@ model Template { createdAt DateTime? @default(now()) @db.Timestamp updatedAt DateTime @updatedAt @db.Timestamp Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) - instanceId String @unique + instanceId String } diff --git a/src/api/services/template.service.ts b/src/api/services/template.service.ts index f5c73f52..d00aec47 100644 --- a/src/api/services/template.service.ts +++ b/src/api/services/template.service.ts @@ -64,6 +64,8 @@ export class TemplateService { throw new Error('Error to create template'); } + console.log(response); + const template = await this.prismaRepository.template.create({ data: { instanceId: getInstance.id,