@@ -282,13 +282,17 @@ function * createSubmission (authUser, files, entity) {
282
282
url : url ,
283
283
memberId : entity . memberId ,
284
284
challengeId,
285
- legacyChallengeId,
286
285
created : currDate ,
287
286
updated : currDate ,
288
287
createdBy : authUser . handle || authUser . sub ,
289
288
updatedBy : authUser . handle || authUser . sub
290
289
}
291
290
291
+ // Pure v5 challenges won't have a legacy challenge id
292
+ if ( legacyChallengeId ) {
293
+ item . legacyChallengeId = legacyChallengeId
294
+ }
295
+
292
296
if ( entity . legacySubmissionId ) {
293
297
item . legacySubmissionId = entity . legacySubmissionId
294
298
}
@@ -405,20 +409,26 @@ function * _updateSubmission (authUser, submissionId, entity) {
405
409
challengeId = yield helper . getV5ChallengeId ( entity . challengeId )
406
410
legacyChallengeId = yield helper . getLegacyChallengeId ( entity . challengeId )
407
411
}
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
+ }
408
419
// Record used for updating in Database
409
420
const record = {
410
421
TableName : table ,
411
422
Key : {
412
423
id : submissionId
413
424
} ,
414
425
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` ,
416
427
ExpressionAttributeValues : {
417
428
':t' : entity . type || exist . type ,
418
429
':u' : entity . url || exist . url ,
419
430
':m' : entity . memberId || exist . memberId ,
420
431
':c' : challengeId ,
421
- ':lc' : legacyChallengeId ,
422
432
':ua' : currDate ,
423
433
':ub' : authUser . handle || authUser . sub ,
424
434
':sb' : entity . submittedDate || exist . submittedDate || exist . created
@@ -429,6 +439,11 @@ function * _updateSubmission (authUser, submissionId, entity) {
429
439
}
430
440
}
431
441
442
+ if ( legacyChallengeId ) {
443
+ record . UpdateExpression = record . UpdateExpression + ', legacyChallengeId = :lc'
444
+ record . ExpressionAttributeValues [ ':lc' ] = legacyChallengeId
445
+ }
446
+
432
447
// If legacy submission ID exists, add it to the update expression
433
448
if ( entity . legacySubmissionId || exist . legacySubmissionId ) {
434
449
record . UpdateExpression = record . UpdateExpression + ', legacySubmissionId = :ls'
0 commit comments