@@ -154,12 +154,15 @@ async function checkErrorV5(res) {
154
154
* Challenge service.
155
155
*/
156
156
class ChallengesService {
157
+
157
158
/**
158
159
* Creates a new ChallengeService instance.
159
160
* @param {String } tokenV3 Optional. Auth token for Topcoder API v3.
160
161
* @param {String } tokenV2 Optional. Auth token for Topcoder API v2.
161
162
*/
162
163
constructor ( tokenV3 , tokenV2 ) {
164
+ const { CHALLENGE_APP_VERSION } = CONFIG ;
165
+
163
166
/**
164
167
* Private function being re-used in all methods related to getting
165
168
* challenges. It handles query-related arguments in the uniform way:
@@ -178,7 +181,8 @@ class ChallengesService {
178
181
&& ! _ . isEqual ( filter . frontFilter . types , [ ] ) ) {
179
182
const query = getFilterUrl ( filter . backendFilter , filter . frontFilter ) ;
180
183
const url = `${ endpoint } ?${ query } ` ;
181
- res = await this . private . apiV5 . get ( url ) . then ( checkErrorV5 ) ;
184
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
185
+ res = await this . private . apiV5 . get ( url , options ) . then ( checkErrorV5 ) ;
182
186
}
183
187
return {
184
188
challenges : res . result || [ ] ,
@@ -202,8 +206,9 @@ class ChallengesService {
202
206
if ( legacyInfo ) {
203
207
query = `legacyId=${ legacyInfo . legacyId } ` ;
204
208
}
205
- const url = `${ endpoint } ?${ query } ` ;
206
- const res = await this . private . apiV5 . get ( url ) . then ( checkErrorV5 ) ;
209
+ const url = `${ endpoint } ?${ query } ` ;
210
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
211
+ const res = await this . private . apiV5 . get ( url , options ) . then ( checkErrorV5 ) ;
207
212
return {
208
213
challenges : res . result || [ ] ,
209
214
} ;
@@ -230,7 +235,8 @@ class ChallengesService {
230
235
memberId,
231
236
} ;
232
237
const url = `${ endpoint } ?${ qs . stringify ( _ . omit ( query , [ 'limit' , 'offset' , 'technologies' ] ) ) } ` ;
233
- const res = await this . private . apiV5 . get ( url ) . then ( checkError ) ;
238
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
239
+ const res = await this . private . apiV5 . get ( url , options ) . then ( checkError ) ;
234
240
const totalCount = res . length ;
235
241
return {
236
242
challenges : res || [ ] ,
@@ -565,7 +571,8 @@ class ChallengesService {
565
571
if ( _ . some ( filter . frontFilter . tracks , val => val )
566
572
&& ! _ . isEqual ( filter . frontFilter . types , [ ] ) ) {
567
573
const url = `/recommender-api/${ handle } ?${ query } ` ;
568
- res = await this . private . apiV5 . get ( url ) . then ( checkErrorV5 ) ;
574
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
575
+ res = await this . private . apiV5 . get ( url , options ) . then ( checkErrorV5 ) ;
569
576
totalCount = res . headers . get ( 'x-total' ) || 0 ;
570
577
}
571
578
@@ -618,7 +625,8 @@ class ChallengesService {
618
625
memberId : userId ,
619
626
} ;
620
627
const url = `/challenges?${ qs . stringify ( _ . omit ( query , [ 'limit' , 'offset' , 'technologies' ] ) ) } ` ;
621
- const userChallenges = await this . private . apiV5 . get ( url )
628
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
629
+ const userChallenges = await this . private . apiV5 . get ( url , options )
622
630
. then ( checkErrorV5 )
623
631
. then ( ( res ) => {
624
632
res . result . forEach ( item => normalizeChallenge ( item , userId ) ) ;
@@ -677,7 +685,8 @@ class ChallengesService {
677
685
memberId,
678
686
} ;
679
687
680
- const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` ) ;
688
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
689
+ const res = await this . private . apiV5 . get ( `/challenges?${ qs . stringify ( newParams ) } ` , options ) ;
681
690
return res . json ( ) ;
682
691
}
683
692
@@ -689,7 +698,8 @@ class ChallengesService {
689
698
*/
690
699
async getUserSrms ( handle , params ) {
691
700
const url = `/members/${ handle } /srms/?${ qs . stringify ( params ) } ` ;
692
- const res = await this . private . api . get ( url ) ;
701
+ const options = { headers : { 'app-version' : CHALLENGE_APP_VERSION } }
702
+ const res = await this . private . api . get ( url , options ) ;
693
703
return getApiResponsePayload ( res ) ;
694
704
}
695
705
0 commit comments