Skip to content

Commit

Permalink
mock recruitment session service, insert data mock
Browse files Browse the repository at this point in the history
  • Loading branch information
whiitex committed Jan 14, 2024
1 parent d4bf3b9 commit c2d69bd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/src/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand Down
24 changes: 24 additions & 0 deletions api/src/recruitment-session/recruitment-session.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Req,
Patch,
ForbiddenException,
Get,
} from '@nestjs/common';
import { RecruitmentSessionService } from './recruitment-session.service';
import {
Expand All @@ -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';
Expand All @@ -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')
Expand All @@ -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()
Expand Down

0 comments on commit c2d69bd

Please sign in to comment.