@@ -112,14 +112,16 @@ class ChallengesService {
112
112
*/
113
113
const getMemberChallenges = async (
114
114
endpoint ,
115
+ filters = { } ,
115
116
params = { } ,
116
117
) => {
117
118
const memberId = decodeToken ( this . private . tokenV3 ) . userId ;
118
119
const query = {
119
120
...params ,
121
+ ...filters ,
120
122
memberId,
121
123
} ;
122
- const url = `${ endpoint } ?${ qs . stringify ( query ) } ` ;
124
+ const url = `${ endpoint } ?${ qs . stringify ( _ . omit ( query , [ 'limit' , 'offset' , 'technologies' ] ) ) } ` ;
123
125
const res = await this . private . apiV5 . get ( url ) . then ( checkError ) ;
124
126
const totalCount = res . length ;
125
127
return {
@@ -132,6 +134,7 @@ class ChallengesService {
132
134
api : getApi ( 'V4' , tokenV3 ) ,
133
135
apiV5 : getApi ( 'V5' , tokenV3 ) ,
134
136
apiV2 : getApi ( 'V2' , tokenV2 ) ,
137
+ apiV3 : getApi ( 'V3' , tokenV3 ) ,
135
138
getChallenges,
136
139
getMemberChallenges,
137
140
tokenV2,
@@ -337,32 +340,39 @@ class ChallengesService {
337
340
338
341
/**
339
342
* Gets challenges of the specified user.
340
- * @param {String } username User whose challenges we want to fetch.
343
+ * @param {String } userId User id whose challenges we want to fetch.
341
344
* @param {Object } filters Optional.
342
345
* @param {Number } params Optional.
343
346
* @return {Promise } Resolves to the api response.
344
347
*/
345
- getUserChallenges ( username , filters , params ) {
346
- // FIXME: This has not been updated to use the V5 API
348
+ getUserChallenges ( userId , filters , params ) {
347
349
const userFilters = _ . cloneDeep ( filters ) ;
348
350
ChallengesService . updateFiltersParamsForGettingMemberChallenges ( userFilters , params ) ;
351
+ const query = {
352
+ ...params ,
353
+ ...userFilters ,
354
+ memberId : userId ,
355
+ } ;
349
356
const endpoint = '/challenges' ;
350
- const res = this . private . getMemberChallenges ( endpoint ) ;
357
+ const url = `${ endpoint } ?${ qs . stringify ( _ . omit ( query , [ 'limit' , 'offset' , 'technologies' ] ) ) } ` ;
358
+
359
+ const res = this . private . apiV5 . get ( url ) ;
351
360
return res ;
352
361
}
353
362
354
363
/**
355
364
* Gets marathon matches of the specified user.
356
- * @param {String } username User whose challenges we want to fetch.
365
+ * @param {String } userId User whose challenges we want to fetch.
357
366
* @param {Object } filters Optional.
358
367
* @param {Number } params Optional.
359
368
* @return {Promise } Resolves to the api response.
360
369
*/
361
- getUserMarathonMatches ( username , filters , params ) {
362
- // FIXME: This has not been updated to use the V5 API
363
- ChallengesService . updateFiltersParamsForGettingMemberChallenges ( filters , params ) ;
364
- const endpoint = `/members/${ username . toLowerCase ( ) } /mms/` ;
365
- return this . private . getMemberChallenges ( endpoint ) ;
370
+ async getUserMarathonMatches ( userId ) {
371
+ const marathonTypeId = 'c2579605-e294-4967-b3db-875ef85240cd' ;
372
+ const url = `/challenges?typeId=${ marathonTypeId } &memberId=${ userId } ` ;
373
+
374
+ const res = await this . private . apiV5 . get ( url ) ;
375
+ return res ;
366
376
}
367
377
368
378
/**
@@ -484,9 +494,9 @@ class ChallengesService {
484
494
* @return {Promise }
485
495
*/
486
496
async updateChallenge ( challenge ) {
487
- const URL = `/challenges/${ challenge . id } ` ;
488
- const body = { param : challenge } ;
489
- let res = await this . private . api . putJson ( URL , body ) ;
497
+ const url = `/challenges/${ challenge . id } ` ;
498
+ const body = { body : challenge } ;
499
+ let res = await this . private . apiV5 . put ( url , body ) ;
490
500
if ( ! res . ok ) throw new Error ( res . statusText ) ;
491
501
res = ( await res . json ( ) ) . result ;
492
502
if ( res . status !== 200 ) throw new Error ( res . content ) ;
@@ -507,10 +517,10 @@ class ChallengesService {
507
517
*/
508
518
async getUserRolesInChallenge ( challengeId ) {
509
519
const user = decodeToken ( this . private . tokenV3 ) ;
510
- const username = user . handle || user . payload . handle ;
511
- const url = `/members/ ${ username . toLowerCase ( ) } /challenges` ;
512
- const data = await this . private . getMemberChallenges ( url , { id : challengeId } ) ;
513
- return data . challenges [ 0 ] . userDetails . roles ;
520
+ const url = `/resources?challengeId= ${ challengeId } ?memberHandle= ${ user . handle } ` ;
521
+ const resources = await this . private . apiV5 ( url ) ;
522
+ if ( resources ) return resources [ 0 ] . roleId ;
523
+ throw new Error ( `Failed to fetch user role from challenge # ${ challengeId } ` ) ;
514
524
}
515
525
}
516
526
0 commit comments