Skip to content

Commit

Permalink
feat: check for conflicts and consistency when updating a recruitment…
Browse files Browse the repository at this point in the history
… session state
  • Loading branch information
AlbertoBaroso committed Jan 21, 2024
1 parent 9190905 commit d0e4524
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions api/src/recruitment-session/recruitment-session.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export class RecruitmentSessionController {
@Patch(':session_id')
@ApiBadRequestResponse()
@ApiForbiddenResponse()
@ApiConflictResponse()
@ApiNotFoundResponse()
@ApiOkResponse()
@JoiValidate({
param: Joi.number().positive().integer().required().label('session_id'),
Expand Down Expand Up @@ -144,9 +146,29 @@ export class RecruitmentSessionController {
)
throw new ForbiddenException();

// TODO: CAN'T SET A RECRUITMENT SESSION TO ACTIVE IF THERE IS ALREADY AN ACTIVE ONE
// TODO: CAN'T SET A RECRUITMENT SESSION TO INACTIVE IF THERE ISN'T AN ACTIVE ONE
// TODO: CAN'T SET A RECRUITMENT SESSION TO INACTIVE IF THERE ARE INTERVIEWS SCHEDULED FOR IT
if (updateRecruitmentSession.hasOwnProperty('state')) {
// There should be only one active recruitment session at a time
if (updateRecruitmentSession.state === RecruitmentSessionState.Active) {
const currentlyActiveRecruitmentSession =
await this.recruitmentSessionService.findActiveRecruitmentSession();
if (currentlyActiveRecruitmentSession)
throw new ConflictException(
'There is already an active recruitment session',
);
} else if (
updateRecruitmentSession.state === RecruitmentSessionState.Concluded
) {
// Recruitment session can't be set to concluded if it has pending interviews
const hasPendingInterviews =
await this.recruitmentSessionService.sessionHasPendingInterviews(
recruitmentSession,
);
if (hasPendingInterviews)
throw new ConflictException(
"Recruitment session can't be set to inactive because it has pending interviews",
);
}
}

const updatedRecruitmentSession =
await this.recruitmentSessionService.updateRecruitmentSession({
Expand Down
2 changes: 1 addition & 1 deletion api/src/recruitment-session/recruitment-session.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ export class RecruitmentSessionService {
recruitmentSession: RecruitmentSession,
): Promise<boolean> {
throw new Error('Method not implemented.');
// TODO: Return true if recruitmentSession.interviews > 0
// TODO: Return true if recruitmentSession.interviews > 0 where interviw date is in the future
}
}

0 comments on commit d0e4524

Please sign in to comment.