Skip to content

Commit

Permalink
Remove template model and related functionality (prisma/postgresql-sc…
Browse files Browse the repository at this point in the history
…hema.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.
  • Loading branch information
dgcode-tec committed Jul 12, 2024
1 parent ca3dadf commit c782305
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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";
12 changes: 0 additions & 12 deletions prisma/postgresql-schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ model Instance {
MessageUpdate MessageUpdate[]
TypebotSession TypebotSession[]
TypebotSetting TypebotSetting?
Template Template[]
}

model Session {
Expand Down Expand Up @@ -306,14 +305,3 @@ model TypebotSetting {
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
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
}
23 changes: 4 additions & 19 deletions src/api/services/template.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Template } from '@prisma/client';
import axios from 'axios';

import { ConfigService, WaBusiness } from '../../config/env.config';
Expand Down Expand Up @@ -39,7 +38,7 @@ export class TemplateService {
return response.data;
}

public async create(instance: InstanceDto, data: TemplateDto): Promise<Template> {
public async create(instance: InstanceDto, data: TemplateDto) {
try {
const getInstance = await this.waMonitor.waInstances[instance.instanceName].instance;

Expand All @@ -61,21 +60,10 @@ export class TemplateService {
const response = await this.requestTemplate(postData, 'POST');

if (!response) {
throw new Error('Error to create template');
return response;
}

console.log(response);

const template = await this.prismaRepository.template.create({
data: {
instanceId: getInstance.id,
templateId: response.id,
name: data.name,
language: data.language,
},
});

return template;
return response;
} catch (error) {
this.logger.error(error);
throw new Error('Error to create template');
Expand All @@ -94,13 +82,10 @@ export class TemplateService {
} else if (method === 'POST') {
const result = await axios.post(urlServer, data, { headers });
return result.data;
} else if (method === 'DELETE') {
const result = await axios.delete(urlServer + '/' + data, { headers });
return result.data;
}
} catch (e) {
this.logger.error(e.response.data);
return null;
return e.response.data.error;
}
}
}

0 comments on commit c782305

Please sign in to comment.