From dd68b4d3a09945730bed79e32ce451d6509aa63e Mon Sep 17 00:00:00 2001 From: Rakib Ansary Date: Mon, 31 Oct 2022 15:07:16 +0600 Subject: [PATCH] feat: challenge phase extension --- .circleci/config.yml | 1 + src/constants.js | 7 +++++- src/services/ProcessorService.js | 37 ++++++++++++++++++-------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3a78bbe..372b1a2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -70,6 +70,7 @@ workflows: branches: only: - develop + - feat/challenge-extension # Production builds are exectuted only on tagged commits to the # master branch. diff --git a/src/constants.js b/src/constants.js index 2e13372..b54e3e4 100644 --- a/src/constants.js +++ b/src/constants.js @@ -10,6 +10,10 @@ const prizeSetTypes = { CheckPoint: 'checkpoint' } +const PhaseTypes = { + POST_MORTEM: 12 +} + const EVENT_ORIGINATOR = 'legacy-challenge-processor' const EVENT_MIME_TYPE = 'application/json' @@ -155,5 +159,6 @@ module.exports = { challengeStatuses, PhaseStatusTypes, prizeTypesIds, - supportedMetadata + supportedMetadata, + PhaseTypes } diff --git a/src/services/ProcessorService.js b/src/services/ProcessorService.js index 1146ada..a93f342 100644 --- a/src/services/ProcessorService.js +++ b/src/services/ProcessorService.js @@ -79,24 +79,28 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService const phasesFromIFx = await timelineService.getChallengePhases(legacyId) logger.debug(`Phases from v5: ${JSON.stringify(v5Phases)}`) logger.debug(`Phases from IFX: ${JSON.stringify(phasesFromIFx)}`) + + let isSubmissionPhaseOpen = false + let postMortemPhaseId = null for (const phase of phasesFromIFx) { + if (phase.phase_type_id === constants.PhaseTypes.POST_MORTEM) { + postMortemPhaseId = phase.project_phase_id + } const phaseName = _.get(_.find(phaseTypes, pt => pt.phase_type_id === phase.phase_type_id), 'name') const v5Equivalent = _.find(v5Phases, p => p.name === phaseName) logger.info(`v4 Phase: ${JSON.stringify(phase)}, v5 Equiv: ${JSON.stringify(v5Equivalent)}`) if (v5Equivalent) { - // Compare duration and status - // if (v5Equivalent.duration * 1000 !== phase.duration * 1 || isSelfService) { - // || - // (v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) || - // (!v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Open)) { - // const newStatus = v5Equivalent.isOpen - // ? constants.PhaseStatusTypes.Open - // : (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed) - // update phase logger.debug(`Will update phase ${phaseName}/${v5Equivalent.name} from ${phase.duration} to duration ${v5Equivalent.duration * 1000} milli`) - const newStatus = v5Equivalent.isOpen - ? constants.PhaseStatusTypes.Open - : (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed) + + let newStatus = v5Equivalent.isOpen ? constants.PhaseStatusTypes.Open : constants.PhaseStatusTypes.Scheduled; + if (v5Equivalent.scheduledEndDate != null && v5Equivalent.scheduledEndDate.trim().length > 0 && new Date().getTime() > new Date(v5Equivalent.scheduledEndDate).getTime()) { + newStatus = constants.PhaseStatusTypes.Closed; + } + + if (v5Equivalent.name === 'Submission' && newStatus === constants.PhaseStatusTypes.Open) { + isSubmissionPhaseOpen = true + } + await timelineService.updatePhase( phase.project_phase_id, legacyId, @@ -105,10 +109,6 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService v5Equivalent.duration * 1000, newStatus // phase.phase_status_id ) - // newStatus) - // } else { - // logger.info(`Durations for ${phaseName} match: ${v5Equivalent.duration * 1000} === ${phase.duration}`) - // } } else { logger.info(`No v5 Equivalent Found for ${phaseName}`) } @@ -116,6 +116,11 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService // make sure to set the required reviewers to 2 await createOrSetNumberOfReviewers(_.toString(phase.project_phase_id), _.toString(numOfReviewers), _.toString(createdBy)) } + + if (isSubmissionPhaseOpen && postMortemPhaseId != null) { + logger.info('Submission Phase is open, Remove Post-Mortem Phase', legacyId, postMortemPhaseId) + await timelineService.dropPhase(legacyId, postMortemPhaseId) + } } // TODO: What about iterative reviews? There can be many for the same challenge. // TODO: handle timeline template updates