@@ -335,7 +335,23 @@ class ChallengeHelper {
335335 }
336336 }
337337
338- enrichChallengeForResponse ( challenge , track , type ) {
338+ /**
339+ * Enrich challenge for API responses. Normalizes dates, phases and ensures
340+ * `track` and `type` fields have a consistent shape.
341+ *
342+ * By default, `track` and `type` are returned as objects:
343+ * track: { id, name, track }
344+ * type: { id, name }
345+ *
346+ * If options.asString === true, `track` and `type` are returned as display strings
347+ * (legacy behavior used for bus events to avoid breaking consumers).
348+ *
349+ * @param {Object } challenge
350+ * @param {Object } [track]
351+ * @param {Object } [type]
352+ * @param {{ asString?: boolean } } [options]
353+ */
354+ enrichChallengeForResponse ( challenge , track , type , options = { } ) {
339355 if ( challenge . phases && challenge . phases . length > 0 ) {
340356 const registrationPhase = _ . find ( challenge . phases , ( p ) => p . name === "Registration" ) ;
341357 const submissionPhase = _ . find ( challenge . phases , ( p ) => p . name === "Submission" ) ;
@@ -385,12 +401,30 @@ class ChallengeHelper {
385401 if ( challenge . endDate )
386402 challenge . endDate = ChallengeHelper . convertDateToISOString ( challenge . endDate ) ;
387403
404+ const asString = options . asString === true ;
405+
388406 if ( track ) {
389- challenge . track = track . name ;
407+ if ( asString ) {
408+ challenge . track = track . name ;
409+ } else {
410+ challenge . track = {
411+ id : track . id ,
412+ name : track . name ,
413+ // Prefer the canonical enum value if present; else derive from name/abbreviation
414+ track : track . track || ( track . abbreviation ? String ( track . abbreviation ) . toUpperCase ( ) : String ( track . name || '' ) . toUpperCase ( ) . replace ( / \s + / g, '_' ) ) ,
415+ } ;
416+ }
390417 }
391418
392419 if ( type ) {
393- challenge . type = type . name ;
420+ if ( asString ) {
421+ challenge . type = type . name ;
422+ } else {
423+ challenge . type = {
424+ id : type . id ,
425+ name : type . name ,
426+ } ;
427+ }
394428 }
395429 if ( challenge . metadata ) {
396430 challenge . metadata = challenge . metadata . map ( ( m ) => {
0 commit comments