diff --git a/server/src/application/application.controller.ts b/server/src/application/application.controller.ts index 98a5075..8d8c12f 100644 --- a/server/src/application/application.controller.ts +++ b/server/src/application/application.controller.ts @@ -38,7 +38,7 @@ export class ApplicationController { private readonly applicationService: ApplicationService, private readonly userService: UserService, private readonly exportService: ExportService, - ) {} + ) { } @Post() @ApiOperation({ summary: 'Créer une nouvelle application' }) @@ -109,7 +109,7 @@ export class ApplicationController { } @Get(':id') - async getApplicationById( + async findOne( @Param('id') id: string, ): Promise { try { @@ -121,6 +121,13 @@ export class ApplicationController { } } + @Get() + @ApiOperation({ summary: 'Récupérer les applications' }) + @ApiResponse({ status: 200, description: 'Liste des applications' }) + async findAll() { + return await this.applicationService.getApplications(); + } + @Patch(':id') async update( @Param('id') id: string, diff --git a/server/src/application/application.service.ts b/server/src/application/application.service.ts index c718f86..17a23d0 100644 --- a/server/src/application/application.service.ts +++ b/server/src/application/application.service.ts @@ -17,7 +17,7 @@ import { Prisma, Application } from '@prisma/client'; @Injectable() export class ApplicationService { applications: any; - constructor(private prisma: PrismaService) {} + constructor(private prisma: PrismaService) { } public async createApplication( ownerId: string, @@ -62,20 +62,20 @@ export class ApplicationService { const whereClause: Prisma.ApplicationWhereInput = { ...(label ? { - label: { - contains: label, - mode: Prisma.QueryMode.insensitive, - }, - } + label: { + contains: label, + mode: Prisma.QueryMode.insensitive, + }, + } : {}), }; const orderByClause: Prisma.Enumerable = - { - metadata: { - updatedAt: 'desc', - }, - }; + { + metadata: { + updatedAt: 'desc', + }, + }; const skip = (page - 1) * limit; @@ -126,6 +126,10 @@ export class ApplicationService { return applicationDto; } + public async getApplications() { + return await this.prisma.application.findMany(); + } + private async createApplicationMetadata(ownerId: string) { const applicationMetadata = await this.prisma.metadata.create({ data: { @@ -162,8 +166,8 @@ export class ApplicationService { plannedDecommissioningDate: createApplicationDto.lifecycle .plannedDecommissioningDate ? new Date( - createApplicationDto.lifecycle.plannedDecommissioningDate, - ) + createApplicationDto.lifecycle.plannedDecommissioningDate, + ) : undefined, metadata: { connect: { id: applicationMetadataId } }, }, @@ -171,12 +175,12 @@ export class ApplicationService { actors: { create: Array.isArray(createApplicationDto.actors) ? createApplicationDto.actors.map((actorDto) => ({ - role: actorDto.role, - user: { connect: { keycloakId: actorDto.userId } }, - externalOrganization: actorDto.organizationId - ? { connect: { id: actorDto.organizationId } } - : undefined, - })) + role: actorDto.role, + user: { connect: { keycloakId: actorDto.userId } }, + externalOrganization: actorDto.organizationId + ? { connect: { id: actorDto.organizationId } } + : undefined, + })) : [], }, compliances: {