@@ -79,24 +79,28 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService
7979 const phasesFromIFx = await timelineService . getChallengePhases ( legacyId )
8080 logger . debug ( `Phases from v5: ${ JSON . stringify ( v5Phases ) } ` )
8181 logger . debug ( `Phases from IFX: ${ JSON . stringify ( phasesFromIFx ) } ` )
82+
83+ let isSubmissionPhaseOpen = false
84+ let postMortemPhaseId = null
8285 for ( const phase of phasesFromIFx ) {
86+ if ( phase . phase_type_id === constants . PhaseTypes . POST_MORTEM ) {
87+ postMortemPhaseId = phase . project_phase_id
88+ }
8389 const phaseName = _ . get ( _ . find ( phaseTypes , pt => pt . phase_type_id === phase . phase_type_id ) , 'name' )
8490 const v5Equivalent = _ . find ( v5Phases , p => p . name === phaseName )
8591 logger . info ( `v4 Phase: ${ JSON . stringify ( phase ) } , v5 Equiv: ${ JSON . stringify ( v5Equivalent ) } ` )
8692 if ( v5Equivalent ) {
87- // Compare duration and status
88- // if (v5Equivalent.duration * 1000 !== phase.duration * 1 || isSelfService) {
89- // ||
90- // (v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) ||
91- // (!v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Open)) {
92- // const newStatus = v5Equivalent.isOpen
93- // ? constants.PhaseStatusTypes.Open
94- // : (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
95- // update phase
9693 logger . debug ( `Will update phase ${ phaseName } /${ v5Equivalent . name } from ${ phase . duration } to duration ${ v5Equivalent . duration * 1000 } milli` )
97- const newStatus = v5Equivalent . isOpen
98- ? constants . PhaseStatusTypes . Open
99- : ( new Date ( ) . getTime ( ) <= new Date ( v5Equivalent . scheduledEndDate ) . getTime ( ) ? constants . PhaseStatusTypes . Scheduled : constants . PhaseStatusTypes . Closed )
94+
95+ let newStatus = v5Equivalent . isOpen ? constants . PhaseStatusTypes . Open : constants . PhaseStatusTypes . Scheduled ;
96+ if ( v5Equivalent . scheduledEndDate != null && v5Equivalent . scheduledEndDate . trim ( ) . length > 0 && new Date ( ) . getTime ( ) > new Date ( v5Equivalent . scheduledEndDate ) . getTime ( ) ) {
97+ newStatus = constants . PhaseStatusTypes . Closed ;
98+ }
99+
100+ if ( v5Equivalent . name === 'Submission' && newStatus === constants . PhaseStatusTypes . Open ) {
101+ isSubmissionPhaseOpen = true
102+ }
103+
100104 await timelineService . updatePhase (
101105 phase . project_phase_id ,
102106 legacyId ,
@@ -105,17 +109,18 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService
105109 v5Equivalent . duration * 1000 ,
106110 newStatus // phase.phase_status_id
107111 )
108- // newStatus)
109- // } else {
110- // logger.info(`Durations for ${phaseName} match: ${v5Equivalent.duration * 1000} === ${phase.duration}`)
111- // }
112112 } else {
113113 logger . info ( `No v5 Equivalent Found for ${ phaseName } ` )
114114 }
115115 if ( isSelfService && phaseName === 'Review' ) {
116116 // make sure to set the required reviewers to 2
117117 await createOrSetNumberOfReviewers ( _ . toString ( phase . project_phase_id ) , _ . toString ( numOfReviewers ) , _ . toString ( createdBy ) )
118118 }
119+
120+ if ( isSubmissionPhaseOpen && postMortemPhaseId != null ) {
121+ logger . info ( 'Submission Phase is open, Remove Post-Mortem Phase' , legacyId , postMortemPhaseId )
122+ await timelineService . dropPhase ( legacyId , postMortemPhaseId )
123+ }
119124 }
120125 // TODO: What about iterative reviews? There can be many for the same challenge.
121126 // TODO: handle timeline template updates
0 commit comments