@@ -146,19 +146,12 @@ class ChallengesService {
146
146
} ;
147
147
const url = `${ endpoint } ?${ qs . stringify ( query ) } ` ;
148
148
const res = await this . private . apiV5 . get ( url ) . then ( checkErrorV5 ) ;
149
-
150
- const memberId = decodeToken ( this . private . tokenV3 ) . userId ;
151
- let myChallenges = { } ;
152
- if ( memberId ) { // if token then check myChallenges count
153
- myChallenges = await this . private . apiV5 . get ( `/resources/${ memberId } /challenges` ) . then ( checkErrorV5 ) ;
154
- }
155
-
156
149
return {
157
150
challenges : res . result || [ ] ,
158
151
totalCount : res . headers . get ( 'x-total' ) ,
159
152
meta : {
160
153
allChallengesCount : res . headers . get ( 'x-total' ) ,
161
- myChallengesCount : ( myChallenges . result && myChallenges . result . length ) || 0 ,
154
+ myChallengesCount : 0 ,
162
155
ongoingChallengesCount : 0 ,
163
156
openChallengesCount : 0 ,
164
157
totalCount : res . headers . get ( 'x-total' ) ,
@@ -450,16 +443,22 @@ class ChallengesService {
450
443
/**
451
444
* Gets challenges of the specified user.
452
445
* @param {String } userId User id whose challenges we want to fetch.
453
- * @param {Object } filters Optional.
454
- * @param {Number } params Optional.
455
446
* @return {Promise } Resolves to the api response.
456
447
*/
457
- getUserChallenges ( userId ) {
448
+ getUserChallenges ( userId , filters , params ) {
449
+ const userFilters = _ . cloneDeep ( filters ) ;
450
+ ChallengesService . updateFiltersParamsForGettingMemberChallenges ( userFilters , params ) ;
458
451
return this . private . apiV5 . get ( `/resources/${ userId } /challenges` )
459
452
. then ( checkErrorV5 ) . then ( ( userChallenges ) => {
460
- const param = { ids : userChallenges . result } ;
461
- const endpoint = `/challenges?${ qs . stringify ( param ) } ` ;
462
- return this . private . apiV5 . get ( endpoint )
453
+ const query = {
454
+ ...params ,
455
+ ...userFilters ,
456
+ ids : userChallenges . result ,
457
+ } ;
458
+ const endpoint = '/challenges' ;
459
+ const url = `${ endpoint } ?${ qs . stringify ( _ . omit ( query , [ 'limit' , 'offset' , 'technologies' ] ) ) } ` ;
460
+
461
+ return this . private . apiV5 . get ( url )
463
462
. then ( checkErrorV5 ) . then ( ( res ) => {
464
463
res . result . forEach ( item => normalizeChallenge ( item , userId ) ) ;
465
464
const newResponse = { } ;
0 commit comments