Skip to content

Commit 6ac2cb4

Browse files
allow pure v5 challenges
1 parent 3accea7 commit 6ac2cb4

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/common/helper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ function * getLegacyChallengeId (challengeId) {
313313
const response = yield request.get(`${config.CHALLENGEAPI_V5_URL}/${challengeId}`)
314314
.set('Authorization', `Bearer ${token}`)
315315
.set('Content-Type', 'application/json')
316+
if (_.get(response.body, 'legacy.pureV5')) {
317+
// pure V5 challenges don't have a legacy ID
318+
return null
319+
}
316320
const legacyId = parseInt(response.body.legacyId, 10)
317321
logger.debug(`Legacy challenge id is ${legacyId} for v5 challenge id ${challengeId}`)
318322
return legacyId

src/services/SubmissionService.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,16 @@ 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+
if (legacyChallengeId) {
292+
item.legacyChallengeId = legacyChallengeId
293+
}
294+
292295
if (entity.legacySubmissionId) {
293296
item.legacySubmissionId = entity.legacySubmissionId
294297
}
@@ -411,13 +414,15 @@ function * _updateSubmission (authUser, submissionId, entity) {
411414
id: submissionId
412415
},
413416
UpdateExpression: `set #type = :t, #url = :u, memberId = :m, challengeId = :c,
414-
legacyChallengeId = :lc, updated = :ua, updatedBy = :ub, submittedDate = :sb`,
417+
${legacyChallengeId ? 'legacyChallengeId = :lc,' : ''} updated = :ua, updatedBy = :ub, submittedDate = :sb`,
415418
ExpressionAttributeValues: {
416419
':t': entity.type || exist.type,
417420
':u': entity.url || exist.url,
418421
':m': entity.memberId || exist.memberId,
419422
':c': challengeId,
420-
':lc': legacyChallengeId,
423+
...(legacyChallengeId ? {
424+
':lc': legacyChallengeId
425+
} : {}),
421426
':ua': currDate,
422427
':ub': authUser.handle || authUser.sub,
423428
':sb': entity.submittedDate || exist.submittedDate || exist.created

0 commit comments

Comments
 (0)