From 5b7212f2b36d66b24d8caca4c6b638b74f056237 Mon Sep 17 00:00:00 2001 From: Cagdas U Date: Sat, 1 May 2021 04:48:10 +0300 Subject: [PATCH] feat(interview-scheduler): add a limit on max. allowed rounds Add a limit on maximum allowed number of interview rounds. --- app-constants.js | 3 ++- src/services/InterviewService.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app-constants.js b/app-constants.js index 2721ddd0..534e46de 100644 --- a/app-constants.js +++ b/app-constants.js @@ -66,7 +66,8 @@ const Interviews = { XaiTemplate: { 'interview-30': 30, 'interview-60': 60 - } + }, + MaxAllowedCount: 3 } const ChallengeStatus = { diff --git a/src/services/InterviewService.js b/src/services/InterviewService.js index e1c57e7e..8dbf17af 100644 --- a/src/services/InterviewService.js +++ b/src/services/InterviewService.js @@ -125,6 +125,11 @@ async function requestInterview (currentUser, jobCandidateId, interview) { const round = await Interview.count({ where: { jobCandidateId } }) + + // throw error if candidate has already had MaxAllowedCount interviews + if (round >= InterviewConstants.MaxAllowedCount) { + throw new errors.ConflictError(`You've reached the maximum allowed number (${InterviewConstants.MaxAllowedCount}) of interviews for this candidate.`) + } interview.round = round + 1 try {