From 541cb723514e3ec5697acf54cfd11ad20265dcfc Mon Sep 17 00:00:00 2001 From: none Date: Fri, 15 Dec 2023 10:20:42 +0100 Subject: [PATCH] feat: controller, Service, Entity, Module, for interview --- api/src/interview/create-interview.dto.ts | 4 ++++ api/src/interview/interview.controller.ts | 27 ++++++++++++++++++----- api/src/interview/interview.service.ts | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/api/src/interview/create-interview.dto.ts b/api/src/interview/create-interview.dto.ts index d5fd379..5c0c074 100644 --- a/api/src/interview/create-interview.dto.ts +++ b/api/src/interview/create-interview.dto.ts @@ -4,6 +4,7 @@ import { ApiProperty } from '@nestjs/swagger'; export class CreateInterviewDto implements Partial { + @ApiProperty() notes: string; @@ -13,6 +14,9 @@ export class CreateInterviewDto implements Partial { @ApiProperty() id_timeslot: number; + @ApiProperty() + id_application: number; + @ApiProperty() interviewer_1: User; diff --git a/api/src/interview/interview.controller.ts b/api/src/interview/interview.controller.ts index df3e784..9969a82 100644 --- a/api/src/interview/interview.controller.ts +++ b/api/src/interview/interview.controller.ts @@ -12,6 +12,8 @@ import { } from '@nestjs/common'; import { Interview } from './interview.entity'; import { InterviewService } from './interview.Service'; +import { TimeSlotsService } from '../timeslots/timeslots.service'; +import { ApplicationsService } from '../application/applications.service'; import { CreateInterviewDto } from './create-interview.dto'; import { UpdateInterviewDto } from './update-interview.dto'; import { @@ -38,7 +40,11 @@ import { Ability } from 'src/authorization/ability.decorator'; @Controller('interview') export class InterviewController { - constructor(private readonly interviewService: InterviewService) {} + constructor( + private readonly interviewService: InterviewService, + private readonly timeSlotService: TimeSlotsService, + private readonly applicationService: ApplicationsService + ) {} @ApiNotFoundResponse() @ApiBadRequestResponse() @@ -109,16 +115,25 @@ export class InterviewController { @JoiValidate({ body: createInterviewSchema, }) + @CheckPolicies((ability) => ability.can(Action.Create, 'Interview')) async create( @Body() interview: CreateInterviewDto, @Ability() ability: AppAbility, @Req() req: AuthenticatedRequest, ): Promise { - if (!checkAbility(ability, Action.Create, interview, 'Interview')){ - throw new ForbiddenException()}; - return this.interviewService.create({ - - }); + const timeslot = await this.timeSlotService.findById(interview.id_timeslot) + if (timeslot === null) { + throw new NotFoundException(); + } + const application = await this.applicationService.findByApplicationId(interview.id_application) + if (application === null) { + throw new NotFoundException(); + } + return this.interviewService.create( + interview, + application, + timeslot + ); } } \ No newline at end of file diff --git a/api/src/interview/interview.service.ts b/api/src/interview/interview.service.ts index 333285d..b60132f 100644 --- a/api/src/interview/interview.service.ts +++ b/api/src/interview/interview.service.ts @@ -22,7 +22,7 @@ export class InterviewService { } async create(interview: CreateInterviewDto, application: Application, timeslot: TimeSlot): Promise { - return await this.interviewRepository.save(interview); + return await this.interviewRepository.save({...interview, application, timeslot}); } async update(interview: Interview): Promise {