Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 129e3c1

Browse files
Merge pull request #120 from eisbilir/PLAT-1711
Plat 1711
2 parents ed7102c + 6c345e4 commit 129e3c1

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

src/services/ProcessorService.js

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -104,43 +104,53 @@ async function syncChallengePhases (legacyId, v5Phases, createdBy, isSelfService
104104
const phasesFromIFx = await timelineService.getChallengePhases(legacyId)
105105
logger.debug(`Phases from v5: ${JSON.stringify(v5Phases)}`)
106106
logger.debug(`Phases from IFX: ${JSON.stringify(phasesFromIFx)}`)
107-
for (const phase of phasesFromIFx) {
108-
const phaseName = _.get(_.find(phaseTypes, pt => pt.phase_type_id === phase.phase_type_id), 'name')
109-
const v5Equivalent = _.find(v5Phases, p => p.name === phaseName)
110-
logger.info(`v4 Phase: ${JSON.stringify(phase)}, v5 Equiv: ${JSON.stringify(v5Equivalent)}`)
111-
if (v5Equivalent) {
112-
// Compare duration and status
113-
// if (v5Equivalent.duration * 1000 !== phase.duration * 1 || isSelfService) {
114-
// ||
115-
// (v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) ||
116-
// (!v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Open)) {
117-
// const newStatus = v5Equivalent.isOpen
118-
// ? constants.PhaseStatusTypes.Open
119-
// : (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
120-
// update phase
121-
logger.debug(`Will update phase ${phaseName}/${v5Equivalent.name} from ${phase.duration} to duration ${v5Equivalent.duration * 1000} milli`)
122-
const newStatus = v5Equivalent.isOpen
123-
? constants.PhaseStatusTypes.Open
124-
: (new Date().getTime() <= new Date(v5Equivalent.scheduledEndDate).getTime() ? constants.PhaseStatusTypes.Scheduled : constants.PhaseStatusTypes.Closed)
125-
await timelineService.updatePhase(
126-
phase.project_phase_id,
127-
legacyId,
128-
phase.fixed_start_time ? v5Equivalent.scheduledStartDate : null,
129-
v5Equivalent.scheduledStartDate,
130-
v5Equivalent.scheduledEndDate,
131-
v5Equivalent.duration * 1000,
132-
newStatus
133-
)
134-
// newStatus)
135-
// } else {
136-
// logger.info(`Durations for ${phaseName} match: ${v5Equivalent.duration * 1000} === ${phase.duration}`)
137-
// }
138-
} else {
139-
logger.info(`No v5 Equivalent Found for ${phaseName}`)
107+
let phaseGroups = {}
108+
_.forEach(phasesFromIFx, p => {
109+
if (!phaseGroups[p.phase_type_id]) {
110+
phaseGroups[p.phase_type_id] = []
140111
}
141-
if (isSelfService && phaseName === 'Review') {
142-
// make sure to set the required reviewers to 2
143-
await createOrSetNumberOfReviewers(_.toString(phase.project_phase_id), _.toString(numOfReviewers), _.toString(createdBy))
112+
phaseGroups[p.phase_type_id].push(p)
113+
})
114+
_.forEach(_.cloneDeep(phaseGroups), (pg, pt) => {
115+
phaseGroups[pt] = _.sortBy(pg, 'scheduled_start_time')
116+
})
117+
118+
for (const key of _.keys(phaseGroups)) {
119+
let phaseOrder = 0
120+
let v5Equivalents = undefined
121+
for (const phase of phaseGroups[key]) {
122+
const phaseName = _.get(_.find(phaseTypes, pt => pt.phase_type_id === phase.phase_type_id), 'name')
123+
if (_.isUndefined(v5Equivalents)) {
124+
v5Equivalents = _.sortBy(_.filter(v5Phases, p => p.name === phaseName), 'scheduledStartDate')
125+
}
126+
if (v5Equivalents.length > 0) {
127+
if (v5Equivalents.length === phaseGroups[key].length) {
128+
const v5Equivalent = v5Equivalents[phaseOrder]
129+
logger.debug(`Will update phase ${phaseName}/${v5Equivalent.name} from ${phase.duration} to duration ${v5Equivalent.duration * 1000} milli`)
130+
let newStatus = _.toInteger(phase.phase_status_id)
131+
if (v5Equivalent.isOpen && _.toInteger(phase.phase_status_id) === constants.PhaseStatusTypes.Closed) {
132+
newStatus = constants.PhaseStatusTypes.Scheduled
133+
}
134+
await timelineService.updatePhase(
135+
phase.project_phase_id,
136+
legacyId,
137+
phase.fixed_start_time ? v5Equivalent.scheduledStartDate : null,
138+
v5Equivalent.scheduledStartDate,
139+
v5Equivalent.scheduledEndDate,
140+
v5Equivalent.duration * 1000,
141+
newStatus
142+
)
143+
} else {
144+
logger.info(`number of ${phaseName} does not match`)
145+
}
146+
} else {
147+
logger.info(`No v5 Equivalent Found for ${phaseName}`)
148+
}
149+
if (isSelfService && phaseName === 'Review') {
150+
// make sure to set the required reviewers to 2
151+
await createOrSetNumberOfReviewers(_.toString(phase.project_phase_id), _.toString(numOfReviewers), _.toString(createdBy))
152+
}
153+
phaseOrder = phaseOrder + 1
144154
}
145155
}
146156
// TODO: What about iterative reviews? There can be many for the same challenge.

0 commit comments

Comments
 (0)