Skip to content

Commit 45c6601

Browse files
committed
fix (challenge extension): throw error when challenge phase and/or start date modification is not allowed
1 parent 82898c8 commit 45c6601

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/services/ChallengeService.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const PhaseService = require('./PhaseService')
1919
const ChallengeTypeService = require('./ChallengeTypeService')
2020
const ChallengeTrackService = require('./ChallengeTrackService')
2121
const ChallengeTimelineTemplateService = require('./ChallengeTimelineTemplateService')
22+
const { BadRequestError } = require('../common/errors')
2223

2324
const esClient = helper.getESClient()
2425

@@ -1524,7 +1525,11 @@ async function update (currentUser, challengeId, data, isFull) {
15241525
}
15251526
}
15261527

1527-
if ((challenge.status === constants.challengeStatuses.Active || challenge.status === constants.challengeStatuses.Draft) && (data.phases || data.startDate)) {
1528+
if (data.phases || data.startDate) {
1529+
if (!(challenge.status === constants.challengeStatuses.Active || challenge.status === constants.challengeStatuses.Draft)) {
1530+
throw new BadRequestError(`Challenge phase/start date can only be modify for "Active" and "Draft" challenges.`)
1531+
}
1532+
15281533
if (data.phases && data.phases.length > 0) {
15291534
for (let i = 0; i < challenge.phases.length; i += 1) {
15301535
const updatedPhaseInfo = _.find(data.phases, p => p.phaseId === challenge.phases[i].phaseId)

0 commit comments

Comments
 (0)