Skip to content

Commit

Permalink
feat: controller, Service, Entity, Module, for interview
Browse files Browse the repository at this point in the history
  • Loading branch information
none authored and none committed Dec 15, 2023
1 parent a9eb49f commit 541cb72
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
4 changes: 4 additions & 0 deletions api/src/interview/create-interview.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ApiProperty } from '@nestjs/swagger';


export class CreateInterviewDto implements Partial<Interview> {

@ApiProperty()
notes: string;

Expand All @@ -13,6 +14,9 @@ export class CreateInterviewDto implements Partial<Interview> {
@ApiProperty()
id_timeslot: number;

@ApiProperty()
id_application: number;

@ApiProperty()
interviewer_1: User;

Expand Down
27 changes: 21 additions & 6 deletions api/src/interview/interview.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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<Interview> {
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
);
}
}

2 changes: 1 addition & 1 deletion api/src/interview/interview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class InterviewService {
}

async create(interview: CreateInterviewDto, application: Application, timeslot: TimeSlot): Promise<Interview> {
return await this.interviewRepository.save(interview);
return await this.interviewRepository.save({...interview, application, timeslot});
}

async update(interview: Interview): Promise<Interview> {
Expand Down

0 comments on commit 541cb72

Please sign in to comment.