From 7f84c872cf658ada6d0c1c9c86e838b546e39baf Mon Sep 17 00:00:00 2001 From: Catalin Oancea Date: Tue, 24 Dec 2024 20:33:37 +0100 Subject: [PATCH] Delete endpoint for custom projects --- backoffice/index.ts | 4 ++-- shared/contracts/custom-projects.contract.ts | 6 +++--- shared/entities/custom-project.entity.ts | 15 +++++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/backoffice/index.ts b/backoffice/index.ts index 176fe8e0..2b58ca85 100644 --- a/backoffice/index.ts +++ b/backoffice/index.ts @@ -210,14 +210,14 @@ const start = async () => { secure: false, maxAge: undefined, }, - }, + } ); app.use(admin.options.rootPath, adminRouter); app.listen(PORT, () => { console.log( - `AdminJS started on http://localhost:${PORT}${admin.options.rootPath}`, + `AdminJS started on http://localhost:${PORT}${admin.options.rootPath}` ); }); }; diff --git a/shared/contracts/custom-projects.contract.ts b/shared/contracts/custom-projects.contract.ts index b01d1b8e..60a1c66d 100644 --- a/shared/contracts/custom-projects.contract.ts +++ b/shared/contracts/custom-projects.contract.ts @@ -96,13 +96,13 @@ export const customProjectContract = contract.router({ }, body: contract.type(), }, - deleteCustomProject: { + deleteCustomProjects: { method: "DELETE", - path: "/custom-projects/:id", + path: "/custom-projects", responses: { 200: contract.type(), }, - body: null, + body: contract.type<{ ids: string[] }>(), }, }); diff --git a/shared/entities/custom-project.entity.ts b/shared/entities/custom-project.entity.ts index 97d68510..226d3ec8 100644 --- a/shared/entities/custom-project.entity.ts +++ b/shared/entities/custom-project.entity.ts @@ -22,13 +22,13 @@ export enum CARBON_REVENUES_TO_COVER { } export enum PROJECT_SPECIFIC_EMISSION { - ONE_EMISSION_FACTOR = 'One emission factor', - TWO_EMISSION_FACTORS = 'Two emission factors', + ONE_EMISSION_FACTOR = "One emission factor", + TWO_EMISSION_FACTORS = "Two emission factors", } export enum PROJECT_EMISSION_FACTORS { - TIER_1 = 'Tier 1 - Global emission factor', - TIER_2 = 'Tier 2 - Country-specific emission factor', - TIER_3 = 'Tier 3 - Project specific emission factor', + TIER_1 = "Tier 1 - Global emission factor", + TIER_2 = "Tier 2 - Country-specific emission factor", + TIER_3 = "Tier 3 - Project specific emission factor", } @Entity({ name: "custom_projects" }) @@ -54,7 +54,10 @@ export class CustomProject { @Column({ name: "abatement_potential", type: "decimal", nullable: true }) abatementPotential?: number; - @ManyToOne(() => User, (user) => user.customProjects, { onDelete: "CASCADE" }) + @ManyToOne(() => User, (user) => user.customProjects, { + onDelete: "CASCADE", + eager: true, + }) @JoinColumn({ name: "user_id" }) user?: User;