@@ -181,6 +181,12 @@ function * downloadSubmission (authUser, submissionId) {
181181 * @return {Object } Data fetched from ES
182182 */
183183function * 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+
184190 const data = yield helper . fetchFromES ( query , helper . camelize ( table ) )
185191 logger . info ( `listSubmissions: returning ${ data . length } submissions for query: ${ JSON . stringify ( query ) } ` )
186192
@@ -200,7 +206,7 @@ const listSubmissionsQuerySchema = {
200206 challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
201207 legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
202208 legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
203- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
209+ submissionPhaseId : joi . id ( ) ,
204210 page : joi . id ( ) ,
205211 perPage : joi . pageSize ( ) ,
206212 orderBy : joi . sortOrder ( ) ,
@@ -262,14 +268,18 @@ function * createSubmission (authUser, files, entity) {
262268 throw new errors . HttpStatusError ( 400 , 'The file should be uploaded under the "submission" attribute' )
263269 }
264270
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+
265275 const currDate = ( new Date ( ) ) . toISOString ( )
266276
267277 const item = {
268278 id : submissionId ,
269279 type : entity . type ,
270280 url : url ,
271281 memberId : entity . memberId ,
272- challengeId : entity . challengeId ,
282+ challengeId : challengeId ,
273283 created : currDate ,
274284 updated : currDate ,
275285 createdBy : authUser . handle || authUser . sub ,
@@ -287,7 +297,7 @@ function * createSubmission (authUser, files, entity) {
287297 if ( entity . submissionPhaseId ) {
288298 item . submissionPhaseId = entity . submissionPhaseId
289299 } else {
290- item . submissionPhaseId = yield helper . getSubmissionPhaseId ( entity . challengeId )
300+ item . submissionPhaseId = yield helper . getSubmissionPhaseId ( challengeId )
291301 }
292302
293303 if ( entity . fileType ) {
@@ -353,7 +363,7 @@ createSubmission.schema = {
353363 challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) . required ( ) ,
354364 legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
355365 legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
356- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) )
366+ submissionPhaseId : joi . id ( )
357367 } ) . required ( )
358368}
359369
@@ -374,6 +384,12 @@ function * _updateSubmission (authUser, submissionId, entity) {
374384 throw new errors . HttpStatusError ( 404 , `Submission with ID = ${ submissionId } is not found` )
375385 }
376386
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+
377393 const currDate = ( new Date ( ) ) . toISOString ( )
378394 // Record used for updating in Database
379395 const record = {
@@ -466,7 +482,7 @@ updateSubmission.schema = {
466482 challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) . required ( ) ,
467483 legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
468484 legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
469- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) )
485+ submissionPhaseId : joi . id ( )
470486 } ) . required ( )
471487}
472488
@@ -491,7 +507,7 @@ patchSubmission.schema = {
491507 challengeId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
492508 legacySubmissionId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
493509 legacyUploadId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) ) ,
494- submissionPhaseId : joi . alternatives ( ) . try ( joi . id ( ) , joi . string ( ) . uuid ( ) )
510+ submissionPhaseId : joi . id ( )
495511 } )
496512}
497513
0 commit comments