Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/common/phase-helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require("lodash");

const { v4: uuid } = require('uuid');
const uuid = require("uuid/v4");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The import statement for uuid has been changed from destructuring to a direct import. This change might break if the uuid package version is updated to a version where v4 is not the default export. Consider using const { v4: uuid } = require('uuid'); to ensure compatibility with future versions.

const moment = require("moment");

const errors = require("./errors");
Expand Down Expand Up @@ -91,6 +91,7 @@ class ChallengePhaseHelper {
timelineTemplateId
);
const { phaseDefinitionMap } = await this.getPhaseDefinitionsAndMap();
const challengePhaseIds = new Set(_.map(challengePhases, "phaseId"));

// Ensure deterministic processing order based on the timeline template sequence
// DB returns phases ordered by dates, which can cause "fixedStartDate" logic below
Expand All @@ -107,9 +108,18 @@ class ChallengePhaseHelper {
const phaseFromTemplate = timelineTemplateMap.get(phase.phaseId);
const phaseDefinition = phaseDefinitionMap.get(phase.phaseId);
const newPhase = _.find(newPhases, (p) => p.phaseId === phase.phaseId);
const templatePredecessor = _.get(phaseFromTemplate, "predecessor");
// Prefer template predecessor only when that phase exists on the challenge, otherwise keep the stored link.
const resolvedPredecessor = _.isNil(phaseFromTemplate)
? phase.predecessor
: _.isNil(templatePredecessor)
? null
: challengePhaseIds.has(templatePredecessor)
? templatePredecessor
: phase.predecessor;
const updatedPhase = {
...phase,
predecessor: phaseFromTemplate && phaseFromTemplate.predecessor,
predecessor: resolvedPredecessor,
description: phaseDefinition.description,
};
if (updatedPhase.name === "Post-Mortem") {
Expand Down Expand Up @@ -157,6 +167,9 @@ class ChallengePhaseHelper {
const predecessorPhase = _.find(updatedPhases, {
phaseId: phase.predecessor,
});
if (_.isNil(predecessorPhase)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 correctness]
The check for _.isNil(predecessorPhase) followed by a continue statement ensures that the loop skips further processing for phases without a valid predecessor. This is correct, but it might be beneficial to log or handle this scenario explicitly if it indicates a potential data inconsistency.

continue;
}
if (phase.name === "Iterative Review") {
if (!iterativeReviewSet) {
if (_.isNil(phase.actualStartDate)) {
Expand Down