Skip to content

Commit 16b7345

Browse files
committed
Add in configurable app version header for challenge API
1 parent 81e04d2 commit 16b7345

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

config/development.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "68c5a381-c8ab-48af-92a7-7a869a4ee6c3",
3-
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "52c91e85-745f-4e62-b592-9879a2dfe9fd"
3+
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "52c91e85-745f-4e62-b592-9879a2dfe9fd",
4+
"CHALLENGE_APP_VERSION": "1.1.0"
45
}

config/production.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"AV_SCAN_SCORER_REVIEW_TYPE_ID": "55bbb17d-aac2-45a6-89c3-a8d102863d05",
3-
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48"
3+
"PROVISIONAL_SCORING_COMPLETED_REVIEW_TYPE_ID": "df51ca7d-fb0a-4147-9569-992fcf5aae48",
4+
"CHALLENGE_APP_VERSION": "1.1.0"
45
}

src/services/challenges.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ async function checkErrorV5(res) {
154154
* Challenge service.
155155
*/
156156
class ChallengesService {
157+
157158
/**
158159
* Creates a new ChallengeService instance.
159160
* @param {String} tokenV3 Optional. Auth token for Topcoder API v3.
160161
* @param {String} tokenV2 Optional. Auth token for Topcoder API v2.
161162
*/
162163
constructor(tokenV3, tokenV2) {
164+
const { CHALLENGE_APP_VERSION } = CONFIG;
165+
163166
/**
164167
* Private function being re-used in all methods related to getting
165168
* challenges. It handles query-related arguments in the uniform way:
@@ -178,7 +181,8 @@ class ChallengesService {
178181
&& !_.isEqual(filter.frontFilter.types, [])) {
179182
const query = getFilterUrl(filter.backendFilter, filter.frontFilter);
180183
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);
182186
}
183187
return {
184188
challenges: res.result || [],
@@ -202,8 +206,9 @@ class ChallengesService {
202206
if (legacyInfo) {
203207
query = `legacyId=${legacyInfo.legacyId}`;
204208
}
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);
207212
return {
208213
challenges: res.result || [],
209214
};
@@ -230,7 +235,8 @@ class ChallengesService {
230235
memberId,
231236
};
232237
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);
234240
const totalCount = res.length;
235241
return {
236242
challenges: res || [],
@@ -565,7 +571,8 @@ class ChallengesService {
565571
if (_.some(filter.frontFilter.tracks, val => val)
566572
&& !_.isEqual(filter.frontFilter.types, [])) {
567573
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);
569576
totalCount = res.headers.get('x-total') || 0;
570577
}
571578

@@ -618,7 +625,8 @@ class ChallengesService {
618625
memberId: userId,
619626
};
620627
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)
622630
.then(checkErrorV5)
623631
.then((res) => {
624632
res.result.forEach(item => normalizeChallenge(item, userId));
@@ -677,7 +685,8 @@ class ChallengesService {
677685
memberId,
678686
};
679687

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);
681690
return res.json();
682691
}
683692

@@ -689,7 +698,8 @@ class ChallengesService {
689698
*/
690699
async getUserSrms(handle, params) {
691700
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);
693703
return getApiResponsePayload(res);
694704
}
695705

0 commit comments

Comments
 (0)