diff --git a/api/src/mocks/data.ts b/api/src/mocks/data.ts index f31aa3e..61b8b02 100644 --- a/api/src/mocks/data.ts +++ b/api/src/mocks/data.ts @@ -11,6 +11,7 @@ import { PhdApplication, } from 'src/application/application.entity'; import { UpdateApplicationDto } from 'src/application/update-application.dto'; +import { RecruitmentSessionState } from '@hkrecruitment/shared/recruitment-session'; export const testDate = new Date(2023, 0, 1); export const testDateTimeStart = new Date(2023, 0, 1, 10, 30, 0); @@ -24,6 +25,25 @@ export const mockTimeSlot = { id: 1, }; +export const testInterviewStart = '11:55' as unknown as Date; +export const testInterviewEnd = '20:35' as unknown as Date; +export const testDay1 = '2024-10-20' as unknown as Date; +export const testDay2 = '2024-10-21' as unknown as Date; +export const testDay3 = '2024-10-22' as unknown as Date; +export const testDateCreatedAt = '2024-9-10' as unknown as Date; +export const testDateLastModified = '2024-9-12' as unknown as Date; + +export const mockRecruitmentSession = { + id: 1, + state: RecruitmentSessionState.Active, + slotDuration: 50, + interviewStart: testInterviewStart, + interviewEnd: testInterviewEnd, + days: [testDay1, testDay2, testDay3], + createdAt: testDateCreatedAt, + lastModified: testDateLastModified, +}; + export const baseFile = { encoding: '7bit', mimetype: 'application/pdf', diff --git a/api/src/recruitment-session/recruitment-session.controller.ts b/api/src/recruitment-session/recruitment-session.controller.ts index a967ad3..0edc0f2 100644 --- a/api/src/recruitment-session/recruitment-session.controller.ts +++ b/api/src/recruitment-session/recruitment-session.controller.ts @@ -10,6 +10,7 @@ import { Req, Patch, ForbiddenException, + Get, } from '@nestjs/common'; import { RecruitmentSessionService } from './recruitment-session.service'; import { @@ -30,6 +31,7 @@ import { ApiTags, ApiConflictResponse, ApiNoContentResponse, + ApiUnauthorizedResponse, } from '@nestjs/swagger'; import { CheckPolicies } from 'src/authorization/check-policies.decorator'; import { CreateRecruitmentSessionDto } from './create-recruitment-session.dto'; @@ -39,6 +41,7 @@ import { Ability } from 'src/authorization/ability.decorator'; import { AuthenticatedRequest } from 'src/authorization/authenticated-request.types'; import { plainToClass } from 'class-transformer'; import { RecruitmentSessionResponseDto } from './recruitment-session-response.dto'; +import { User } from 'src/users/user.entity'; @ApiBearerAuth() @ApiTags('recruitment-session') @@ -48,6 +51,27 @@ export class RecruitmentSessionController { private readonly recruitmentSessionService: RecruitmentSessionService, ) {} + // FIND ACTIVE RECRUITMENT SESSION + @ApiNotFoundResponse() + @ApiUnauthorizedResponse() + @Get() + @CheckPolicies((ability) => ability.can(Action.Read, 'RecruitmentSession')) + async findActive( + @Ability() ability: AppAbility, + ): Promise<RecruitmentSession> { + const recruitmentSession = + await this.recruitmentSessionService.findActiveRecruitmentSession(); + if (recruitmentSession === null) { + throw new NotFoundException(); + } + + if (!checkAbility(ability, Action.Read, recruitmentSession, 'Person')) { + throw new ForbiddenException(); + } + + return recruitmentSession; + } + // CREATE NEW RECRUITMENT SESSION @ApiBadRequestResponse() @ApiForbiddenResponse()