@@ -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