@@ -181,6 +181,12 @@ function * downloadSubmission (authUser, submissionId) {
181
181
* @return {Object } Data fetched from ES
182
182
*/
183
183
function * listSubmissions ( authUser , query ) {
184
+ if ( query . challengeId ) {
185
+ // Submission api only works with legacy challenge id
186
+ // If it is a v5 challenge id, get the associated legacy challenge id
187
+ query . challengeId = yield helper . getLegacyChallengeId ( query . challengeId )
188
+ }
189
+
184
190
const data = yield helper . fetchFromES ( query , helper . camelize ( table ) )
185
191
logger . info ( `listSubmissions: returning ${ data . length } submissions for query: ${ JSON . stringify ( query ) } ` )
186
192
@@ -200,7 +206,7 @@ const listSubmissionsQuerySchema = {
200
206
challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
201
207
legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
202
208
legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
203
- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
209
+ submissionPhaseId : joi . id ( ) ,
204
210
page : joi . id ( ) ,
205
211
perPage : joi . pageSize ( ) ,
206
212
orderBy : joi . sortOrder ( ) ,
@@ -262,14 +268,18 @@ function * createSubmission (authUser, files, entity) {
262
268
throw new errors . HttpStatusError ( 400 , 'The file should be uploaded under the "submission" attribute' )
263
269
}
264
270
271
+ // Submission api only works with legacy challenge id
272
+ // If it is a v5 challenge id, get the associated legacy challenge id
273
+ const challengeId = yield helper . getLegacyChallengeId ( entity . challengeId )
274
+
265
275
const currDate = ( new Date ( ) ) . toISOString ( )
266
276
267
277
const item = {
268
278
id : submissionId ,
269
279
type : entity . type ,
270
280
url : url ,
271
281
memberId : entity . memberId ,
272
- challengeId : entity . challengeId ,
282
+ challengeId : challengeId ,
273
283
created : currDate ,
274
284
updated : currDate ,
275
285
createdBy : authUser . handle || authUser . sub ,
@@ -287,7 +297,7 @@ function * createSubmission (authUser, files, entity) {
287
297
if ( entity . submissionPhaseId ) {
288
298
item . submissionPhaseId = entity . submissionPhaseId
289
299
} else {
290
- item . submissionPhaseId = yield helper . getSubmissionPhaseId ( entity . challengeId )
300
+ item . submissionPhaseId = yield helper . getSubmissionPhaseId ( challengeId )
291
301
}
292
302
293
303
if ( entity . fileType ) {
@@ -353,7 +363,7 @@ createSubmission.schema = {
353
363
challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) . required ( ) ,
354
364
legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
355
365
legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
356
- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) )
366
+ submissionPhaseId : joi . id ( )
357
367
} ) . required ( )
358
368
}
359
369
@@ -374,6 +384,12 @@ function * _updateSubmission (authUser, submissionId, entity) {
374
384
throw new errors . HttpStatusError ( 404 , `Submission with ID = ${ submissionId } is not found` )
375
385
}
376
386
387
+ if ( entity . challengeId ) {
388
+ // Submission api only works with legacy challenge id
389
+ // If it is a v5 challenge id, get the associated legacy challenge id
390
+ entity . challengeId = yield helper . getLegacyChallengeId ( entity . challengeId )
391
+ }
392
+
377
393
const currDate = ( new Date ( ) ) . toISOString ( )
378
394
// Record used for updating in Database
379
395
const record = {
@@ -466,7 +482,7 @@ updateSubmission.schema = {
466
482
challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) . required ( ) ,
467
483
legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
468
484
legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
469
- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) )
485
+ submissionPhaseId : joi . id ( )
470
486
} ) . required ( )
471
487
}
472
488
@@ -491,7 +507,7 @@ patchSubmission.schema = {
491
507
challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
492
508
legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
493
509
legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
494
- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) )
510
+ submissionPhaseId : joi . id ( )
495
511
} )
496
512
}
497
513
0 commit comments