Skip to content

Commit

Permalink
feat: ✨ backEnd route get all applications
Browse files Browse the repository at this point in the history
  • Loading branch information
KomsteRr committed Dec 20, 2024
1 parent eea313c commit 5f50067
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
11 changes: 9 additions & 2 deletions server/src/application/application.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })
Expand Down Expand Up @@ -109,7 +109,7 @@ export class ApplicationController {
}

@Get(':id')
async getApplicationById(
async findOne(
@Param('id') id: string,
): Promise<GetApplicationDto> {
try {
Expand All @@ -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,
Expand Down
42 changes: 23 additions & 19 deletions server/src/application/application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Prisma.ApplicationOrderByWithRelationInput> =
{
metadata: {
updatedAt: 'desc',
},
};
{
metadata: {
updatedAt: 'desc',
},
};

const skip = (page - 1) * limit;

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -162,21 +166,21 @@ export class ApplicationService {
plannedDecommissioningDate: createApplicationDto.lifecycle
.plannedDecommissioningDate
? new Date(
createApplicationDto.lifecycle.plannedDecommissioningDate,
)
createApplicationDto.lifecycle.plannedDecommissioningDate,
)
: undefined,
metadata: { connect: { id: applicationMetadataId } },
},
},
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: {
Expand Down

0 comments on commit 5f50067

Please sign in to comment.