@@ -363,6 +363,22 @@ class ChallengesService {
363
363
) ) ;
364
364
}
365
365
366
+ /**
367
+ * Get the ID from a challenge type by abbreviation
368
+ * @param {String } abbreviation
369
+ * @return {Promise } ID from first abbreviation match
370
+ */
371
+ async getChallengeTypeId ( abbreviation ) {
372
+ const ret = await this . private . apiV5 . get ( `/challenge-types?abbreviation=${ abbreviation } ` )
373
+ . then ( checkErrorV5 ) . then ( res => res ) ;
374
+
375
+ if ( _ . isEmpty ( ret . result ) ) {
376
+ throw new Error ( 'Challenge typeId not found!' ) ;
377
+ }
378
+
379
+ return ret . result [ 0 ] . id ;
380
+ }
381
+
366
382
/**
367
383
* Gets possible challenge tags (technologies).
368
384
* @return {Promise } Resolves to the array of tag strings.
@@ -394,11 +410,10 @@ class ChallengesService {
394
410
/**
395
411
* Gets SRM matches.
396
412
* @param {Object } params
397
- * @param {string } typeId Challenge SRM TypeId
398
413
* @return {Promise }
399
414
*/
400
415
async getSrms ( params ) {
401
- const res = await this . private . apiV5 . get ( `/challenges /?${ qs . stringify ( params ) } ` ) ;
416
+ const res = await this . private . api . get ( `/srms /?${ qs . stringify ( params ) } ` ) ;
402
417
return getApiResponsePayload ( res ) ;
403
418
}
404
419
@@ -438,17 +453,25 @@ class ChallengesService {
438
453
439
454
/**
440
455
* Gets marathon matches of the specified user.
441
- * @param {String } userId User whose challenges we want to fetch.
442
- * @param {Object } filters Optional.
443
- * @param {Number } params Optional.
456
+ * @param {String } memberId User whose challenges we want to fetch.
457
+ * @param {Object } params
444
458
* @return {Promise } Resolves to the api response.
445
459
*/
446
- async getUserMarathonMatches ( userId ) {
447
- const marathonTypeId = 'c2579605-e294-4967-b3db-875ef85240cd' ;
448
- const url = `/challenges?typeId=${ marathonTypeId } &memberId=${ userId } ` ;
460
+ async getUserMarathonMatches ( memberId , params ) {
461
+ const typeId = await this . getChallengeTypeId ( 'DEVELOP_MARATHON_MATCH' ) ;
449
462
450
- const res = await this . private . apiV5 . get ( url ) ;
451
- return res ;
463
+ if ( ! typeId ) {
464
+ return null ;
465
+ }
466
+
467
+ const newParams = {
468
+ ...params ,
469
+ typeId,
470
+ memberId,
471
+ } ;
472
+
473
+ const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` ) ;
474
+ return getApiResponsePayload ( res ) ;
452
475
}
453
476
454
477
/**
@@ -458,18 +481,8 @@ class ChallengesService {
458
481
* @return {Promise }
459
482
*/
460
483
async getUserSrms ( handle , params ) {
461
- const challenges = await this . private . apiV5 . get ( `/resources?memberHandle=${ handle } ` ) ;
462
- let newParams = params ;
463
- if ( challenges ) {
464
- const { challengeId } = challenges [ 0 ] ;
465
- newParams = {
466
- ...params ,
467
- challengeId,
468
- } ;
469
- }
470
-
471
- const url = `/challenges/${ qs . stringify ( newParams ) } ` ;
472
- const res = await this . private . apiV5 . get ( url ) ;
484
+ const url = `/members/${ handle } /srms/?${ qs . stringify ( params ) } ` ;
485
+ const res = await this . private . api . get ( url ) ;
473
486
return getApiResponsePayload ( res ) ;
474
487
}
475
488
0 commit comments