Skip to content

Commit 4067285

Browse files
Merge branch 'dev' of https://github.com/topcoder-platform/challenge-api into fix/PLAT-2567
2 parents 933002a + 8e46d7b commit 4067285

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/common/phase-helper.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ class ChallengePhaseHelper {
170170
return updatedPhases;
171171
}
172172

173+
handlePhasesAfterCancelling(phases) {
174+
return _.map(phases, (phase) => {
175+
if (_.includes(["Registration", "Submission", "Checkpoint Submission"], phase.name)) {
176+
phase.isOpen = false;
177+
if (!_.isUndefined(phase.actualStartDate)) {
178+
phase.actualEndDate = moment().toDate().toISOString();
179+
}
180+
}
181+
});
182+
}
183+
173184
async validatePhases(phases) {
174185
if (!phases || phases.length === 0) {
175186
return;

src/services/ChallengeService.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,7 @@ async function updateChallenge(currentUser, challengeId, data) {
16061606
/* END self-service stuffs */
16071607

16081608
let isChallengeBeingActivated = false;
1609+
let isChallengeBeingCancelled = false;
16091610
if (data.status) {
16101611
if (data.status === constants.challengeStatuses.Active) {
16111612
if (
@@ -1631,6 +1632,32 @@ async function updateChallenge(currentUser, challengeId, data) {
16311632
}
16321633
}
16331634

1635+
if (_.includes([
1636+
constants.challengeStatuses.Cancelled,
1637+
constants.challengeStatuses.CancelledRequirementsInfeasible,
1638+
constants.challengeStatuses.CancelledPaymentFailed,
1639+
constants.challengeStatuses.CancelledFailedReview,
1640+
constants.challengeStatuses.CancelledFailedScreening,
1641+
constants.challengeStatuses.CancelledZeroSubmissions,
1642+
constants.challengeStatuses.CancelledWinnerUnresponsive,
1643+
constants.challengeStatuses.CancelledClientRequest,
1644+
constants.challengeStatuses.CancelledZeroRegistrations,
1645+
], data.status)) {
1646+
isChallengeBeingCancelled = true;
1647+
}
1648+
1649+
if (
1650+
data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
1651+
data.status === constants.challengeStatuses.CancelledPaymentFailed
1652+
) {
1653+
try {
1654+
await helper.cancelProject(challenge.projectId, cancelReason, currentUser);
1655+
} catch (e) {
1656+
logger.debug(`There was an error trying to cancel the project: ${e.message}`);
1657+
}
1658+
sendRejectedEmail = true;
1659+
}
1660+
16341661
if (data.status === constants.challengeStatuses.Completed) {
16351662
if (
16361663
!_.get(challenge, "legacy.pureV5Task") &&
@@ -1723,9 +1750,9 @@ async function updateChallenge(currentUser, challengeId, data) {
17231750

17241751
let phasesUpdated = false;
17251752
if (
1726-
(data.phases && data.phases.length > 0) ||
1753+
((data.phases && data.phases.length > 0) ||
17271754
isChallengeBeingActivated ||
1728-
timelineTemplateChanged
1755+
timelineTemplateChanged) && !isChallengeBeingCancelled
17291756
) {
17301757
if (
17311758
challenge.status === constants.challengeStatuses.Completed ||
@@ -1754,6 +1781,10 @@ async function updateChallenge(currentUser, challengeId, data) {
17541781
phasesUpdated = true;
17551782
data.phases = newPhases;
17561783
}
1784+
if (isChallengeBeingCancelled) {
1785+
data.phases = await phaseHelper.handlePhasesAfterCancelling(challenge.phases);
1786+
phasesUpdated = true;
1787+
}
17571788
if (phasesUpdated || data.startDate) {
17581789
data.startDate = convertToISOString(_.min(_.map(data.phases, "scheduledStartDate")));
17591790
}

0 commit comments

Comments
 (0)