@@ -340,6 +340,22 @@ class ChallengesService {
340
340
) ) ;
341
341
}
342
342
343
+ /**
344
+ * Get the ID from a challenge type by abbreviation
345
+ * @param {String } abbreviation
346
+ * @return {Promise } ID from first abbreviation match
347
+ */
348
+ async getChallengeTypeId ( abbreviation ) {
349
+ const ret = await this . private . apiV5 . get ( `/challenge-types?abbreviation=${ abbreviation } ` )
350
+ . then ( checkErrorV5 ) . then ( res => res ) ;
351
+
352
+ if ( _ . isEmpty ( ret . result ) ) {
353
+ throw new Error ( 'Challenge typeId not found!' ) ;
354
+ }
355
+
356
+ return ret . result [ 0 ] . id ;
357
+ }
358
+
343
359
/**
344
360
* Gets possible challenge tags (technologies).
345
361
* @return {Promise } Resolves to the array of tag strings.
@@ -375,7 +391,17 @@ class ChallengesService {
375
391
* @return {Promise }
376
392
*/
377
393
async getSrms ( params ) {
378
- const res = await this . private . apiV5 . get ( `/challenges/?${ qs . stringify ( params ) } ` ) ;
394
+ const typeId = await this . getChallengeTypeId ( 'DEVELOP_SINGLE_ROUND_MATCH' ) ;
395
+ if ( ! typeId ) {
396
+ return null ;
397
+ }
398
+
399
+ const newParams = {
400
+ ...params ,
401
+ typeId,
402
+ } ;
403
+
404
+ const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` ) ;
379
405
return getApiResponsePayload ( res ) ;
380
406
}
381
407
@@ -415,17 +441,25 @@ class ChallengesService {
415
441
416
442
/**
417
443
* Gets marathon matches of the specified user.
418
- * @param {String } userId User whose challenges we want to fetch.
419
- * @param {Object } filters Optional.
420
- * @param {Number } params Optional.
444
+ * @param {String } memberId User whose challenges we want to fetch.
445
+ * @param {Object } params
421
446
* @return {Promise } Resolves to the api response.
422
447
*/
423
- async getUserMarathonMatches ( userId ) {
424
- const marathonTypeId = 'c2579605-e294-4967-b3db-875ef85240cd' ;
425
- const url = `/challenges?typeId=${ marathonTypeId } &memberId=${ userId } ` ;
448
+ async getUserMarathonMatches ( memberId , params ) {
449
+ const typeId = await this . getChallengeTypeId ( 'DEVELOP_MARATHON_MATCH' ) ;
450
+
451
+ if ( ! typeId ) {
452
+ return null ;
453
+ }
426
454
427
- const res = await this . private . apiV5 . get ( url ) ;
428
- return res ;
455
+ const newParams = {
456
+ ...params ,
457
+ typeId,
458
+ memberId,
459
+ } ;
460
+
461
+ const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` ) ;
462
+ return getApiResponsePayload ( res ) ;
429
463
}
430
464
431
465
/**
@@ -435,18 +469,19 @@ class ChallengesService {
435
469
* @return {Promise }
436
470
*/
437
471
async getUserSrms ( memberId , params ) {
438
- const challenges = await this . private . apiV5 . get ( `/resources/${ memberId } /challenges` ) ;
439
- let newParams = params ;
440
- if ( challenges ) {
441
- const { challengeId } = challenges [ 0 ] ;
442
- newParams = {
443
- ...params ,
444
- challengeId,
445
- } ;
472
+ const typeId = await this . getChallengeTypeId ( 'DEVELOP_SINGLE_ROUND_MATCH' ) ;
473
+
474
+ if ( ! typeId ) {
475
+ return null ;
446
476
}
447
477
448
- const url = `/challenges/${ qs . stringify ( newParams ) } ` ;
449
- const res = await this . private . apiV5 . get ( url ) ;
478
+ const newParams = {
479
+ ...params ,
480
+ typeId,
481
+ memberId,
482
+ } ;
483
+
484
+ const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` ) ;
450
485
return getApiResponsePayload ( res ) ;
451
486
}
452
487
0 commit comments