Skip to content

Conversation

@jmgasper
Copy link
Contributor

Allow for Topgear Submission type phase when calculating start / end dates (PS-444)
@jmgasper jmgasper merged commit 0f5d076 into develop Nov 12, 2025
5 checks passed
const { ensureAcessibilityToModifiedGroups } = require("./group-helper");
const { ChallengeStatusEnum } = require("@prisma/client");

const SUBMISSION_PHASE_PRIORITY = ["Topcoder Submission", "Submission"];

Choose a reason for hiding this comment

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

[💡 maintainability]
Consider making SUBMISSION_PHASE_PRIORITY a constant outside of this file if it is used in multiple places across the codebase. This will improve maintainability by ensuring that changes to the priority list are centralized.

const registrationPhase = _.find(challenge.phases, (p) => p.name === "Registration");
const submissionPhase = _.find(challenge.phases, (p) => p.name === "Submission");
const submissionPhase =
_.find(challenge.phases, (p) => p.name === SUBMISSION_PHASE_PRIORITY[0]) ||

Choose a reason for hiding this comment

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

[⚠️ performance]
The logic for finding the submissionPhase could be optimized by using a single _.find with a predicate that checks for both names in SUBMISSION_PHASE_PRIORITY. This reduces redundancy and improves performance slightly.


const registrationPhase = _.find(phases, (p) => p.name === "Registration");
const submissionPhase =
_.find(phases, (p) => p.name === SUBMISSION_PHASE_PRIORITY[0]) ||

Choose a reason for hiding this comment

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

[⚠️ correctness]
The use of SUBMISSION_PHASE_PRIORITY array to find the submissionPhase is a good approach for flexibility. However, consider adding a check to ensure that at least one submission phase is found. If neither 'Topcoder Submission' nor 'Submission' phases exist, submissionPhase will be undefined, which might lead to unexpected behavior when accessing its properties later.

});

if (dependentOpenPhases.length === 0) {
const normalizedPhaseName = normalizePhaseName(phaseName);

Choose a reason for hiding this comment

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

[💡 maintainability]
The variable normalizedPhaseName is declared but not used in the subsequent logic. Consider removing it if it's unnecessary or ensure it's used correctly if it was intended for a specific purpose.

if (dependentOpenPhases.length === 0) {
const normalizedPhaseName = normalizePhaseName(phaseName);
const hasSubmissionVariantOpen = openPhases.some((phase) =>
SUBMISSION_PHASE_NAME_SET.has(normalizePhaseName(phase?.name))

Choose a reason for hiding this comment

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

[⚠️ correctness]
The use of optional chaining phase?.name is good for safety, but ensure that all code paths that rely on phase.name being non-null are correctly handled. If phase.name is null or undefined, normalizePhaseName will return an empty string, which may not be the intended behavior in all cases.

})

try {
const challengePhase = await service.partiallyUpdateChallengePhase(

Choose a reason for hiding this comment

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

[⚠️ maintainability]
Consider adding error handling for the partiallyUpdateChallengePhase call to ensure any exceptions are properly caught and logged. This will help in diagnosing issues if the update fails unexpectedly.

should.equal(challengePhase.isOpen, true)
should.equal(challengePhase.actualEndDate, null)
} finally {
await prisma.challengePhase.update({

Choose a reason for hiding this comment

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

[❗❗ correctness]
Ensure that the finally block correctly handles any exceptions that might occur during the prisma.challengePhase.update calls. If an error occurs here, it could leave the database in an inconsistent state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants