@@ -370,6 +370,22 @@ class ChallengesService {
370
370
) ) ;
371
371
}
372
372
373
+ /**
374
+ * Get the ID from a challenge type by abbreviation
375
+ * @param {String } abbreviation
376
+ * @return {Promise } ID from first abbreviation match
377
+ */
378
+ async getChallengeTypeId ( abbreviation ) {
379
+ const ret = await this . private . apiV5 . get ( `/challenge-types?abbreviation=${ abbreviation } ` )
380
+ . then ( checkErrorV5 ) . then ( res => res ) ;
381
+
382
+ if ( _ . isEmpty ( ret . result ) ) {
383
+ throw new Error ( 'Challenge typeId not found!' ) ;
384
+ }
385
+
386
+ return ret . result [ 0 ] . id ;
387
+ }
388
+
373
389
/**
374
390
* Gets possible challenge tags (technologies).
375
391
* @return {Promise } Resolves to the array of tag strings.
@@ -401,11 +417,10 @@ class ChallengesService {
401
417
/**
402
418
* Gets SRM matches.
403
419
* @param {Object } params
404
- * @param {string } typeId Challenge SRM TypeId
405
420
* @return {Promise }
406
421
*/
407
422
async getSrms ( params ) {
408
- const res = await this . private . apiV5 . get ( `/challenges /?${ qs . stringify ( params ) } ` ) ;
423
+ const res = await this . private . api . get ( `/srms /?${ qs . stringify ( params ) } ` ) ;
409
424
return getApiResponsePayload ( res ) ;
410
425
}
411
426
@@ -445,17 +460,25 @@ class ChallengesService {
445
460
446
461
/**
447
462
* Gets marathon matches of the specified user.
448
- * @param {String } userId User whose challenges we want to fetch.
449
- * @param {Object } filters Optional.
450
- * @param {Number } params Optional.
463
+ * @param {String } memberId User whose challenges we want to fetch.
464
+ * @param {Object } params
451
465
* @return {Promise } Resolves to the api response.
452
466
*/
453
- async getUserMarathonMatches ( userId ) {
454
- const marathonTypeId = 'c2579605-e294-4967-b3db-875ef85240cd' ;
455
- const url = `/challenges?typeId=${ marathonTypeId } &memberId=${ userId } ` ;
467
+ async getUserMarathonMatches ( memberId , params ) {
468
+ const typeId = await this . getChallengeTypeId ( 'DEVELOP_MARATHON_MATCH' ) ;
456
469
457
- const res = await this . private . apiV5 . get ( url ) ;
458
- return res ;
470
+ if ( ! typeId ) {
471
+ return null ;
472
+ }
473
+
474
+ const newParams = {
475
+ ...params ,
476
+ typeId,
477
+ memberId,
478
+ } ;
479
+
480
+ const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` ) ;
481
+ return getApiResponsePayload ( res ) ;
459
482
}
460
483
461
484
/**
@@ -465,18 +488,8 @@ class ChallengesService {
465
488
* @return {Promise }
466
489
*/
467
490
async getUserSrms ( handle , params ) {
468
- const challenges = await this . private . apiV5 . get ( `/resources?memberHandle=${ handle } ` ) ;
469
- let newParams = params ;
470
- if ( challenges ) {
471
- const { challengeId } = challenges [ 0 ] ;
472
- newParams = {
473
- ...params ,
474
- challengeId,
475
- } ;
476
- }
477
-
478
- const url = `/challenges/${ qs . stringify ( newParams ) } ` ;
479
- const res = await this . private . apiV5 . get ( url ) ;
491
+ const url = `/members/${ handle } /srms/?${ qs . stringify ( params ) } ` ;
492
+ const res = await this . private . api . get ( url ) ;
480
493
return getApiResponsePayload ( res ) ;
481
494
}
482
495
0 commit comments