@@ -298,6 +298,7 @@ function * createSubmission (authUser, files, entity) {
298298 updatedBy : authUser . handle || authUser . sub
299299 }
300300
301+ // Pure v5 challenges won't have a legacy challenge id
301302 if ( legacyChallengeId ) {
302303 item . legacyChallengeId = legacyChallengeId
303304 }
@@ -343,6 +344,7 @@ function * createSubmission (authUser, files, entity) {
343344 }
344345
345346 logger . info ( 'Prepared submission item to insert into Dynamodb. Inserting...' )
347+ logger . info ( JSON . stringify ( record , null , 2 ) )
346348 yield dbhelper . insertRecord ( record )
347349
348350 // After save to db, adjust challengeId to busApi and response
@@ -417,6 +419,13 @@ function * _updateSubmission (authUser, submissionId, entity) {
417419 challengeId = yield helper . getV5ChallengeId ( entity . challengeId )
418420 legacyChallengeId = yield helper . getLegacyChallengeId ( entity . challengeId )
419421 }
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+ }
420429 // Record used for updating in Database
421430 const record = {
422431 TableName : table ,
@@ -443,6 +452,11 @@ function * _updateSubmission (authUser, submissionId, entity) {
443452 }
444453 }
445454
455+ if ( legacyChallengeId ) {
456+ record . UpdateExpression = record . UpdateExpression + ', legacyChallengeId = :lc'
457+ record . ExpressionAttributeValues [ ':lc' ] = legacyChallengeId
458+ }
459+
446460 // If legacy submission ID exists, add it to the update expression
447461 if ( entity . legacySubmissionId || exist . legacySubmissionId ) {
448462 record . UpdateExpression = record . UpdateExpression + ', legacySubmissionId = :ls'
0 commit comments