@@ -298,6 +298,7 @@ function * createSubmission (authUser, files, entity) {
298
298
updatedBy : authUser . handle || authUser . sub
299
299
}
300
300
301
+ // Pure v5 challenges won't have a legacy challenge id
301
302
if ( legacyChallengeId ) {
302
303
item . legacyChallengeId = legacyChallengeId
303
304
}
@@ -343,6 +344,7 @@ function * createSubmission (authUser, files, entity) {
343
344
}
344
345
345
346
logger . info ( 'Prepared submission item to insert into Dynamodb. Inserting...' )
347
+ logger . info ( JSON . stringify ( record , null , 2 ) )
346
348
yield dbhelper . insertRecord ( record )
347
349
348
350
// After save to db, adjust challengeId to busApi and response
@@ -417,6 +419,13 @@ function * _updateSubmission (authUser, submissionId, entity) {
417
419
challengeId = yield helper . getV5ChallengeId ( entity . challengeId )
418
420
legacyChallengeId = yield helper . getLegacyChallengeId ( entity . challengeId )
419
421
}
422
+ if ( exist . legacyChallengeId && ! legacyChallengeId ) {
423
+ // Original submission contains a legacy challenge id
424
+ // But with this update, it does not
425
+ // Prevent updates to current submission
426
+ // else we will be left with a submission with wrong legacy challenge id
427
+ throw new errors . HttpStatusError ( 400 , `Cannot update submission with v5 challenge id since it already has a legacy challenge id associated with it` )
428
+ }
420
429
// Record used for updating in Database
421
430
const record = {
422
431
TableName : table ,
@@ -443,6 +452,11 @@ function * _updateSubmission (authUser, submissionId, entity) {
443
452
}
444
453
}
445
454
455
+ if ( legacyChallengeId ) {
456
+ record . UpdateExpression = record . UpdateExpression + ', legacyChallengeId = :lc'
457
+ record . ExpressionAttributeValues [ ':lc' ] = legacyChallengeId
458
+ }
459
+
446
460
// If legacy submission ID exists, add it to the update expression
447
461
if ( entity . legacySubmissionId || exist . legacySubmissionId ) {
448
462
record . UpdateExpression = record . UpdateExpression + ', legacySubmissionId = :ls'
0 commit comments