Skip to content

Commit 793100b

Browse files
Merge pull request #254 from topcoder-platform/Issue_253
HOTFIX - do not store legacy challenge id if there isnt one
2 parents 89c3730 + 08ca508 commit 793100b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/common/helper.js

+2
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ function adjustSubmissionChallengeId (submission) {
766766
if (submission.challengeId && submission.legacyChallengeId) {
767767
submission.v5ChallengeId = submission.challengeId
768768
submission.challengeId = submission.legacyChallengeId
769+
} else if (submission.challengeId && !submission.legacyChallengeId) {
770+
submission.v5ChallengeId = submission.challengeId
769771
}
770772
}
771773

src/services/SubmissionService.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,17 @@ function * createSubmission (authUser, files, entity) {
282282
url: url,
283283
memberId: entity.memberId,
284284
challengeId,
285-
legacyChallengeId,
286285
created: currDate,
287286
updated: currDate,
288287
createdBy: authUser.handle || authUser.sub,
289288
updatedBy: authUser.handle || authUser.sub
290289
}
291290

291+
// Pure v5 challenges won't have a legacy challenge id
292+
if (legacyChallengeId) {
293+
item.legacyChallengeId = legacyChallengeId
294+
}
295+
292296
if (entity.legacySubmissionId) {
293297
item.legacySubmissionId = entity.legacySubmissionId
294298
}
@@ -405,20 +409,26 @@ function * _updateSubmission (authUser, submissionId, entity) {
405409
challengeId = yield helper.getV5ChallengeId(entity.challengeId)
406410
legacyChallengeId = yield helper.getLegacyChallengeId(entity.challengeId)
407411
}
412+
if (exist.legacyChallengeId && !legacyChallengeId) {
413+
// Original submission contains a legacy challenge id
414+
// But with this update, it does not
415+
// Prevent updates to current submission
416+
// else we will be left with a submission with wrong legacy challenge id
417+
throw new errors.HttpStatusError(400, `Cannot update submission with v5 challenge id since it already has a legacy challenge id associated with it`)
418+
}
408419
// Record used for updating in Database
409420
const record = {
410421
TableName: table,
411422
Key: {
412423
id: submissionId
413424
},
414425
UpdateExpression: `set #type = :t, #url = :u, memberId = :m, challengeId = :c,
415-
legacyChallengeId = :lc, updated = :ua, updatedBy = :ub, submittedDate = :sb`,
426+
updated = :ua, updatedBy = :ub, submittedDate = :sb`,
416427
ExpressionAttributeValues: {
417428
':t': entity.type || exist.type,
418429
':u': entity.url || exist.url,
419430
':m': entity.memberId || exist.memberId,
420431
':c': challengeId,
421-
':lc': legacyChallengeId,
422432
':ua': currDate,
423433
':ub': authUser.handle || authUser.sub,
424434
':sb': entity.submittedDate || exist.submittedDate || exist.created
@@ -429,6 +439,11 @@ function * _updateSubmission (authUser, submissionId, entity) {
429439
}
430440
}
431441

442+
if (legacyChallengeId) {
443+
record.UpdateExpression = record.UpdateExpression + ', legacyChallengeId = :lc'
444+
record.ExpressionAttributeValues[':lc'] = legacyChallengeId
445+
}
446+
432447
// If legacy submission ID exists, add it to the update expression
433448
if (entity.legacySubmissionId || exist.legacySubmissionId) {
434449
record.UpdateExpression = record.UpdateExpression + ', legacySubmissionId = :ls'

0 commit comments

Comments
 (0)