From 97ee0fd0916631b4a3cd71fb07c03d041794fa18 Mon Sep 17 00:00:00 2001 From: Caroline Robillard <45307611+Carolinedanslesnuages@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:18:33 +0100 Subject: [PATCH] refactor: :fire: remove fields uri & url from Prisma schema and associated code (#144) --- .../migrations/20241209140539_/migration.sql | 10 +++++ server/prisma/schema/applications.prisma | 2 - server/src/application/application.service.ts | 37 +------------------ .../application/dto/create-application.dto.ts | 18 --------- .../application/dto/get-application.dto.ts | 6 --- 5 files changed, 12 insertions(+), 61 deletions(-) create mode 100644 server/prisma/migrations/20241209140539_/migration.sql diff --git a/server/prisma/migrations/20241209140539_/migration.sql b/server/prisma/migrations/20241209140539_/migration.sql new file mode 100644 index 0000000..f88c068 --- /dev/null +++ b/server/prisma/migrations/20241209140539_/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to drop the column `uri` on the `applications` table. All the data in the column will be lost. + - You are about to drop the column `url` on the `applications` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "applications" DROP COLUMN "uri", +DROP COLUMN "url"; diff --git a/server/prisma/schema/applications.prisma b/server/prisma/schema/applications.prisma index b34355e..ec80f9a 100644 --- a/server/prisma/schema/applications.prisma +++ b/server/prisma/schema/applications.prisma @@ -4,8 +4,6 @@ model Application { shortName String? logo String? description String - url String - uri String purposes String[] tags String[] lifecycleId String diff --git a/server/src/application/application.service.ts b/server/src/application/application.service.ts index a562df5..47bd9a0 100644 --- a/server/src/application/application.service.ts +++ b/server/src/application/application.service.ts @@ -4,30 +4,18 @@ import { BadRequestException, NotFoundException, Logger, - InternalServerErrorException, } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; import { CreateApplicationDto } from './dto/create-application.dto'; import { UpdateApplicationDto } from './dto/update-application.dto'; import { SearchApplicationDto } from './dto/search-application.dto'; import { GetApplicationDto } from './dto/get-application.dto'; -import { ConfigService } from '@nestjs/config'; import { Prisma } from '@prisma/client'; @Injectable() export class ApplicationService { applications: any; - private readonly BASE_URL_APPLICATION: string; - private readonly BASE_URL_API: string; - constructor( - private prisma: PrismaService, - private configService: ConfigService, - ) { - this.BASE_URL_APPLICATION = this.configService.get( - 'BASE_URL_APPLICATION', - ); - this.BASE_URL_API = this.configService.get('BASE_URL_API'); - } + constructor(private prisma: PrismaService) {} public async createApplication( ownerId: string, @@ -52,8 +40,7 @@ export class ApplicationService { applicationMetadata.id, createApplicationDto, ); - const updatedApplication = await this.updateApplicationUrls(application.id); - return updatedApplication; + return application; } public async updateApplication( @@ -159,8 +146,6 @@ export class ApplicationService { shortName: application.shortName || null, logo: application.logo || null, description: application.description, - url: application.url, - uri: application.uri, purposes: application.purposes, tags: application.tags, lifecycleId: application.lifecycleId || null, @@ -193,8 +178,6 @@ export class ApplicationService { shortName: createApplicationDto.shortName || null, logo: createApplicationDto.logo || null, description: createApplicationDto.description, - url: createApplicationDto.url || this.BASE_URL_APPLICATION, - uri: createApplicationDto.uri || this.BASE_URL_API, purposes: createApplicationDto.purposes, tags: createApplicationDto.tags, metadata: { connect: { id: applicationMetadataId } }, @@ -261,22 +244,6 @@ export class ApplicationService { return application; } - private async updateApplicationUrls(applicationId: string) { - return await this.prisma.application.update({ - where: { id: applicationId }, - data: { - url: `${this.BASE_URL_APPLICATION}/${applicationId}`, - uri: `${this.BASE_URL_API}/${applicationId}`, - }, - include: { - lifecycle: { include: { metadata: true } }, - metadata: true, - actors: true, - compliances: true, - }, - }); - } - private async isApplicationExist(applicationId: string): Promise { const application = await this.prisma.application.findUnique({ where: { id: applicationId }, diff --git a/server/src/application/dto/create-application.dto.ts b/server/src/application/dto/create-application.dto.ts index a5bd668..2b3ee6f 100644 --- a/server/src/application/dto/create-application.dto.ts +++ b/server/src/application/dto/create-application.dto.ts @@ -212,24 +212,6 @@ export class CreateApplicationDto { @IsString({ each: true }) tags?: string[]; - @ApiProperty({ - example: 'http://example.com/app', - description: 'URI of the application', - required: false, - }) - @IsOptional() - @IsString() - uri?: string; - - @ApiProperty({ - example: 'http://example.com/dashboard', - description: 'URL of the application', - required: false, - }) - @IsOptional() - @IsString() - url?: string; - @ApiProperty({ example: 'parentApp123', description: 'Parent application ID', diff --git a/server/src/application/dto/get-application.dto.ts b/server/src/application/dto/get-application.dto.ts index c8b2576..8ea84ba 100644 --- a/server/src/application/dto/get-application.dto.ts +++ b/server/src/application/dto/get-application.dto.ts @@ -17,12 +17,6 @@ export class GetApplicationDto { @IsString() description: string; - @IsString() - url: string; - - @IsString() - uri: string; - @IsArray() purposes: string[];