Remove template model and related functionality (prisma/postgresql-schema.prisma, src/api/services/template.service.ts)

This commit removes the Template model, including its related functionality, from the project. The template table has been removed from the database schema, and all related functions and methods in the template service have been deleted. This change was made because the project now uses the persistence of the meta, eliminating the need for a separate template model.

Please note that this change may affect other parts of the application that rely on the Template model. Ensure that all necessary adjustments have been made before merging this commit.
This commit is contained in:
Davidson Gomes 2024-07-12 13:25:59 -03:00
parent ca3dadfb35
commit c782305456
3 changed files with 15 additions and 31 deletions

View File

@ -0,0 +1,11 @@
/*
Warnings:
- You are about to drop the `Template` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Template" DROP CONSTRAINT "Template_instanceId_fkey";
-- DropTable
DROP TABLE "Template";

View File

@ -75,7 +75,6 @@ model Instance {
MessageUpdate MessageUpdate[] MessageUpdate MessageUpdate[]
TypebotSession TypebotSession[] TypebotSession TypebotSession[]
TypebotSetting TypebotSetting? TypebotSetting TypebotSetting?
Template Template[]
} }
model Session { model Session {
@ -306,14 +305,3 @@ model TypebotSetting {
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade) Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String @unique instanceId String @unique
} }
model Template {
id String @id @default(cuid())
name String @db.VarChar(255)
language String @db.VarChar(255)
templateId String @unique @db.VarChar(255)
createdAt DateTime? @default(now()) @db.Timestamp
updatedAt DateTime @updatedAt @db.Timestamp
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
instanceId String
}

View File

@ -1,4 +1,3 @@
import { Template } from '@prisma/client';
import axios from 'axios'; import axios from 'axios';
import { ConfigService, WaBusiness } from '../../config/env.config'; import { ConfigService, WaBusiness } from '../../config/env.config';
@ -39,7 +38,7 @@ export class TemplateService {
return response.data; return response.data;
} }
public async create(instance: InstanceDto, data: TemplateDto): Promise<Template> { public async create(instance: InstanceDto, data: TemplateDto) {
try { try {
const getInstance = await this.waMonitor.waInstances[instance.instanceName].instance; const getInstance = await this.waMonitor.waInstances[instance.instanceName].instance;
@ -61,21 +60,10 @@ export class TemplateService {
const response = await this.requestTemplate(postData, 'POST'); const response = await this.requestTemplate(postData, 'POST');
if (!response) { if (!response) {
throw new Error('Error to create template'); return response;
} }
console.log(response); return response;
const template = await this.prismaRepository.template.create({
data: {
instanceId: getInstance.id,
templateId: response.id,
name: data.name,
language: data.language,
},
});
return template;
} catch (error) { } catch (error) {
this.logger.error(error); this.logger.error(error);
throw new Error('Error to create template'); throw new Error('Error to create template');
@ -94,13 +82,10 @@ export class TemplateService {
} else if (method === 'POST') { } else if (method === 'POST') {
const result = await axios.post(urlServer, data, { headers }); const result = await axios.post(urlServer, data, { headers });
return result.data; return result.data;
} else if (method === 'DELETE') {
const result = await axios.delete(urlServer + '/' + data, { headers });
return result.data;
} }
} catch (e) { } catch (e) {
this.logger.error(e.response.data); this.logger.error(e.response.data);
return null; return e.response.data.error;
} }
} }
} }