Skip to content

Commit b5e045b

Browse files
committedDec 14, 2018
Fix code quality issues from V4 changes
1 parent 626aa51 commit b5e045b

File tree

11 files changed

+64
-103
lines changed

11 files changed

+64
-103
lines changed
 

‎.eslintrc

+1-37
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
11
{
2-
"extends": "./node_modules/topcoder-react-utils/config/eslint/default.json",
3-
"rules": {
4-
"jsx-a11y/label-has-for": [
5-
2,
6-
{
7-
"components": [
8-
"Label"
9-
],
10-
"required": {
11-
"some": [
12-
"nesting",
13-
"id"
14-
]
15-
},
16-
"allowChildren": false
17-
}
18-
],
19-
"jsx-a11y/label-has-associated-control": [
20-
2,
21-
{
22-
"labelComponents": [
23-
"CustomLabel"
24-
],
25-
"labelAttributes": [
26-
"inputLabel"
27-
],
28-
"controlComponents": [
29-
"CustomInput"
30-
],
31-
"depth": 3
32-
}
33-
],
34-
"no-unused-vars": 0,
35-
"no-undef": 0,
36-
"react/jsx-no-undef": 0,
37-
"react/require-default-props": 0
38-
}
2+
"extends": "./node_modules/topcoder-react-utils/config/eslint/default.json"
393
}

‎__tests__/__snapshots__/index.js.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ Object {
309309
"Iterative Review": "Iterative Review",
310310
"Spec Review": "Specification Review",
311311
},
312-
"getApiResponsePayloadV3": [Function],
313-
"getApiResponsePayloadV4": [Function],
312+
"getApiResponsePayload": [Function],
313+
"getLookerApiResponsePayload": [Function],
314314
},
315315
"time": Object {
316316
"default": undefined,

‎docs/tc.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ Collection of small Topcoder-related functions.
1010

1111
* [tc](#module_tc)
1212
* [.REVIEW_OPPORTUNITY_TYPES](#module_tc.REVIEW_OPPORTUNITY_TYPES)
13-
* [.getApiResponsePayloadV3(res)](#module_tc.getApiResponsePayloadV3) ⇒ <code>Promise</code>
13+
* [.getApiResponsePayload(res)](#module_tc.getApiResponsePayload) ⇒ <code>Promise</code>
1414

1515
<a name="module_tc.REVIEW_OPPORTUNITY_TYPES"></a>
1616

1717
### tc.REVIEW_OPPORTUNITY_TYPES
1818
Review Opportunity types
1919

2020
**Kind**: static constant of [<code>tc</code>](#module_tc)
21-
<a name="module_tc.getApiResponsePayloadV3"></a>
21+
<a name="module_tc.getApiResponsePayload"></a>
2222

23-
### tc.getApiResponsePayloadV3(res) ⇒ <code>Promise</code>
24-
Gets payload from a standard success response from TC API v3; or throws
23+
### tc.getApiResponsePayload(res) ⇒ <code>Promise</code>
24+
Gets payload from a standard success response from TC API; or throws
2525
an error in case of a failure response.
2626

2727
**Kind**: static method of [<code>tc</code>](#module_tc)

‎src/services/api.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { config, isomorphy } from 'topcoder-react-utils';
99
import { delay } from '../utils/time';
1010
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
1111

12-
// config.API.V4 = 'https://api.topcoder.com/v4';
13-
1412
/* The minimal delay [ms] between API calls. To avoid problems with the requests
1513
* rate limits configured in Topcoder APIs, we throttle requests rate at the
1614
* client side, and at server-side, in dev mode (which is meant to be used for

‎src/services/challenges.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import qs from 'qs';
1010
import { decodeToken } from 'tc-accounts';
1111
import logger from '../utils/logger';
1212
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
13-
import { COMPETITION_TRACKS, getApiResponsePayloadV3 } from '../utils/tc';
14-
import { getApiV2, getApiV3, getApiV4 } from './api';
13+
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
14+
import { getApiV2, getApiV4 } from './api';
1515

1616
export const ORDER_BY = {
1717
SUBMISSION_END_DATE: 'submissionEndDate',
@@ -86,7 +86,7 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
8686
registrants: v4.registrants || [],
8787
};
8888

89-
// v4 Winners have different field names, needs to be normalized to match v4 filtered and v3
89+
// v4 Winners have different field names, needs to be normalized to match v4 filtered and v4
9090
challenge.winners = _.map(
9191
v4.winners,
9292
(winner, index) => ({
@@ -117,22 +117,22 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
117117
componentId: v4Filtered.componentId,
118118
contestId: v4Filtered.contestId,
119119

120-
submissionEndDate: v4Filtered.submissionEndDate, // Dates are not correct in v3
121-
submissionEndTimestamp: v4Filtered.submissionEndDate, // Dates are not correct in v3
120+
submissionEndDate: v4Filtered.submissionEndDate, // Dates are not correct in v4
121+
submissionEndTimestamp: v4Filtered.submissionEndDate, // Dates are not correct in v4
122122

123-
/* Taking phases from v3_filtered, because dates are not correct in v3 */
123+
/* Taking phases from v4_filtered, because dates are not correct in v4 */
124124
allPhases: v4Filtered.allPhases || [],
125125

126-
/* Taking phases from v3_filtered, because dates are not correct in v3 */
126+
/* Taking phases from v4_filtered, because dates are not correct in v4 */
127127
currentPhases: v4Filtered.currentPhases || [],
128128

129-
/* v3 returns incorrect value for numberOfSubmissions for some reason */
129+
/* v4 returns incorrect value for numberOfSubmissions for some reason */
130130
numSubmissions: v4Filtered.numSubmissions,
131131
groups,
132132
});
133133
}
134134

135-
// Fill missing data from v3_user
135+
// Fill missing data from v4_user
136136
if (v4User) {
137137
_.defaults(challenge, {
138138
userDetails: v4User.userDetails,
@@ -168,7 +168,7 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
168168
* Normalizes a regular challenge object received from the backend.
169169
* NOTE: This function is copied from the existing code in the challenge listing
170170
* component. It is possible, that this normalization is not necessary after we
171-
* have moved to Topcoder API v3, but it is kept for now to minimize a risk of
171+
* have moved to Topcoder API v4, but it is kept for now to minimize a risk of
172172
* breaking anything.
173173
* @todo Should be used only internally!
174174
* @param {Object} challenge Challenge object received from the backend.
@@ -251,7 +251,7 @@ class ChallengesService {
251251
...params,
252252
};
253253
const url = `${endpoint}?${qs.stringify(query)}`;
254-
const res = await this.private.apiV4.get(url).then(checkError);
254+
const res = await this.private.api.get(url).then(checkError);
255255
return {
256256
challenges: res.content || [],
257257
totalCount: res.metadata.totalCount,
@@ -261,7 +261,6 @@ class ChallengesService {
261261
this.private = {
262262
api: getApiV4(tokenV3),
263263
apiV2: getApiV2(tokenV2),
264-
apiV4: getApiV4(tokenV3),
265264
getChallenges,
266265
tokenV2,
267266
tokenV3,
@@ -359,14 +358,14 @@ class ChallengesService {
359358

360359
/**
361360
* Gets challenge details from Topcoder API v4.
362-
* NOTE: This function also uses API v2 and other v3 endpoints for now, due
361+
* NOTE: This function also uses API v2 and other v4 endpoints for now, due
363362
* to some information is missing or
364-
* incorrect in the main v3 endpoint. This may change in the future.
363+
* incorrect in the main v4 endpoint. This may change in the future.
365364
* @param {Number|String} challengeId
366365
* @return {Promise} Resolves to the challenge object.
367366
*/
368367
async getChallengeDetails(challengeId) {
369-
const challengeV4 = await this.private.apiV4.get(`/challenges/${challengeId}`)
368+
const challengeV4 = await this.private.api.get(`/challenges/${challengeId}`)
370369
.then(checkError).then(res => res.content);
371370

372371
const challengeV4Filtered = await this.private.getChallenges('/challenges/', { id: challengeId })
@@ -437,7 +436,7 @@ class ChallengesService {
437436
*/
438437
async getSrms(params) {
439438
const res = await this.private.api.get(`/srms/?${qs.stringify(params)}`);
440-
return getApiResponsePayloadV3(res);
439+
return getApiResponsePayload(res);
441440
}
442441

443442
/**
@@ -466,7 +465,7 @@ class ChallengesService {
466465
async getUserSrms(handle, params) {
467466
const url = `/members/${handle}/srms/?${qs.stringify(params)}`;
468467
const res = await this.private.api.get(url);
469-
return getApiResponsePayloadV3(res);
468+
return getApiResponsePayload(res);
470469
}
471470

472471
/**
@@ -476,7 +475,7 @@ class ChallengesService {
476475
*/
477476
async register(challengeId) {
478477
const endpoint = `/challenges/${challengeId}/register`;
479-
const res = await this.private.apiV4.postJson(endpoint);
478+
const res = await this.private.api.postJson(endpoint);
480479
if (!res.ok) throw new Error(res.statusText);
481480
return res.json();
482481
}
@@ -488,7 +487,7 @@ class ChallengesService {
488487
*/
489488
async unregister(challengeId) {
490489
const endpoint = `/challenges/${challengeId}/unregister`;
491-
const res = await this.private.apiV4.post(endpoint);
490+
const res = await this.private.api.post(endpoint);
492491
if (!res.ok) throw new Error(res.statusText);
493492
return res.json();
494493
}

‎src/services/looker.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @desc This module provides a service to get look data json
44
* via API V4.
55
*/
6-
import { getApiResponsePayloadV4 } from '../utils/tc';
6+
import { getLookerApiResponsePayload } from '../utils/tc';
77
import { getApiV4 } from './api';
88

99
/**
@@ -27,7 +27,7 @@ class LookerService {
2727
*/
2828
async getLooker(lookerId) {
2929
const res = await this.private.api.get(`/looks/${lookerId}/run/json`);
30-
return getApiResponsePayloadV4(res);
30+
return getLookerApiResponsePayload(res);
3131
}
3232
}
3333

‎src/services/lookup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* via API V3.
55
*/
66
import qs from 'qs';
7-
import { getApiResponsePayloadV3 } from '../utils/tc';
7+
import { getApiResponsePayload } from '../utils/tc';
88
import { getApiV3 } from './api';
99

1010
class LookupService {
@@ -25,7 +25,7 @@ class LookupService {
2525
*/
2626
async getTags(params) {
2727
const res = await this.private.api.get(`/tags/?${qs.stringify(params)}`);
28-
return getApiResponsePayloadV3(res);
28+
return getApiResponsePayload(res);
2929
}
3030
}
3131

‎src/services/members.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import _ from 'lodash';
99
import qs from 'qs';
1010
import logger from '../utils/logger';
11-
import { getApiResponsePayloadV3 } from '../utils/tc';
11+
import { getApiResponsePayload } from '../utils/tc';
1212
import { getApiV3 } from './api';
1313

1414
/**
@@ -32,7 +32,7 @@ class MembersService {
3232
*/
3333
async getMemberFinances(handle) {
3434
const res = await this.private.api.get(`/members/${handle}/financial`);
35-
return getApiResponsePayloadV3(res);
35+
return getApiResponsePayload(res);
3636
}
3737

3838
/**
@@ -45,7 +45,7 @@ class MembersService {
4545
*/
4646
async getMemberInfo(handle) {
4747
const res = await this.private.api.get(`/members/${handle}`);
48-
return getApiResponsePayloadV3(res);
48+
return getApiResponsePayload(res);
4949
}
5050

5151
/**
@@ -55,7 +55,7 @@ class MembersService {
5555
*/
5656
async getExternalAccounts(handle) {
5757
const res = await this.private.api.get(`/members/${handle}/externalAccounts`);
58-
return getApiResponsePayloadV3(res);
58+
return getApiResponsePayload(res);
5959
}
6060

6161
/**
@@ -65,7 +65,7 @@ class MembersService {
6565
*/
6666
async getExternalLinks(handle) {
6767
const res = await this.private.api.get(`/members/${handle}/externalLinks`);
68-
return getApiResponsePayloadV3(res);
68+
return getApiResponsePayload(res);
6969
}
7070

7171
/**
@@ -75,7 +75,7 @@ class MembersService {
7575
*/
7676
async getSkills(handle) {
7777
const res = await this.private.api.get(`/members/${handle}/skills`);
78-
return getApiResponsePayloadV3(res);
78+
return getApiResponsePayload(res);
7979
}
8080

8181
/**
@@ -85,7 +85,7 @@ class MembersService {
8585
*/
8686
async getStats(handle) {
8787
const res = await this.private.api.get(`/members/${handle}/stats`);
88-
return getApiResponsePayloadV3(res);
88+
return getApiResponsePayload(res);
8989
}
9090

9191
/**
@@ -95,7 +95,7 @@ class MembersService {
9595
*/
9696
async getStatsHistory(handle) {
9797
const res = await this.private.api.get(`/members/${handle}/stats/history`);
98-
return getApiResponsePayloadV3(res);
98+
return getApiResponsePayload(res);
9999
}
100100

101101
/**
@@ -110,7 +110,7 @@ class MembersService {
110110
track,
111111
subTrack,
112112
}))}`);
113-
return getApiResponsePayloadV3(res);
113+
return getApiResponsePayload(res);
114114
}
115115

116116
/**
@@ -123,7 +123,7 @@ class MembersService {
123123
*/
124124
async getMemberSuggestions(keyword) {
125125
const res = await this.private.api.get(`/members/_suggest/${keyword}`);
126-
return getApiResponsePayloadV3(res);
126+
return getApiResponsePayload(res);
127127
}
128128

129129
/**
@@ -134,7 +134,7 @@ class MembersService {
134134
*/
135135
async addWebLink(userHandle, webLink) {
136136
const res = await this.private.api.postJson(`/members/${userHandle}/externalLinks`, { param: { url: webLink } });
137-
return getApiResponsePayloadV3(res);
137+
return getApiResponsePayload(res);
138138
}
139139

140140
/**
@@ -150,7 +150,7 @@ class MembersService {
150150
},
151151
};
152152
const res = await this.private.api.delete(`/members/${userHandle}/externalLinks/${webLinkHandle}`, JSON.stringify(body));
153-
return getApiResponsePayloadV3(res);
153+
return getApiResponsePayload(res);
154154
}
155155

156156
/**
@@ -170,7 +170,7 @@ class MembersService {
170170
},
171171
};
172172
const res = await this.private.api.patchJson(`/members/${handle}/skills`, body);
173-
return getApiResponsePayloadV3(res);
173+
return getApiResponsePayload(res);
174174
}
175175

176176
/**
@@ -193,7 +193,7 @@ class MembersService {
193193
body: JSON.stringify(body),
194194
method: 'PATCH',
195195
});
196-
return getApiResponsePayloadV3(res);
196+
return getApiResponsePayload(res);
197197
}
198198

199199
/**
@@ -203,7 +203,7 @@ class MembersService {
203203
*/
204204
async updateMemberProfile(profile) {
205205
const res = await this.private.api.putJson(`/members/${profile.handle}`, { param: profile });
206-
return getApiResponsePayloadV3(res);
206+
return getApiResponsePayload(res);
207207
}
208208

209209
/**
@@ -214,7 +214,7 @@ class MembersService {
214214
*/
215215
async getPresignedUrl(userHandle, file) {
216216
const res = await this.private.api.postJson(`/members/${userHandle}/photoUploadUrl`, { param: { contentType: file.type } });
217-
const payload = await getApiResponsePayloadV3(res);
217+
const payload = await getApiResponsePayload(res);
218218

219219
return {
220220
preSignedURL: payload.preSignedURL,
@@ -231,7 +231,7 @@ class MembersService {
231231
*/
232232
async updateMemberPhoto(S3Response) {
233233
const res = await this.private.api.putJson(`/members/${S3Response.userHandle}/photo`, { param: S3Response.body });
234-
return getApiResponsePayloadV3(res);
234+
return getApiResponsePayload(res);
235235
}
236236

237237
/**

‎src/services/user-traits.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* via API V3.
55
*/
66
import toCapitalCase from 'to-capital-case';
7-
import { getApiResponsePayloadV3 } from '../utils/tc';
7+
import { getApiResponsePayload } from '../utils/tc';
88
import { getApiV3 } from './api';
99

1010
/**
@@ -29,7 +29,7 @@ class UserTraitsService {
2929
async getAllUserTraits(handle) {
3030
// FIXME: Remove the .toLowerCase() when the API is fixed to ignore the case in the route params
3131
const res = await this.private.api.get(`/members/${handle.toLowerCase()}/traits`);
32-
return getApiResponsePayloadV3(res);
32+
return getApiResponsePayload(res);
3333
}
3434

3535
/**
@@ -51,7 +51,7 @@ class UserTraitsService {
5151
};
5252

5353
const res = await this.private.api.postJson(`/members/${handle}/traits`, body);
54-
return getApiResponsePayloadV3(res);
54+
return getApiResponsePayload(res);
5555
}
5656

5757
/**
@@ -73,7 +73,7 @@ class UserTraitsService {
7373
};
7474

7575
const res = await this.private.api.putJson(`/members/${handle}/traits`, body);
76-
return getApiResponsePayloadV3(res);
76+
return getApiResponsePayload(res);
7777
}
7878

7979
/**
@@ -84,7 +84,7 @@ class UserTraitsService {
8484
*/
8585
async deleteUserTrait(handle, traitId) {
8686
const res = await this.private.api.delete(`/members/${handle}/traits?traitIds=${traitId}`);
87-
return getApiResponsePayloadV3(res);
87+
return getApiResponsePayload(res);
8888
}
8989
}
9090

‎src/services/user.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { config, isomorphy } from 'topcoder-react-utils';
77

88
import logger from '../utils/logger';
9-
import { getApiResponsePayloadV3 } from '../utils/tc';
9+
import { getApiResponsePayload } from '../utils/tc';
1010
import { getApiV2, getApiV3 } from './api';
1111

1212
let auth0;
@@ -152,7 +152,7 @@ class User {
152152
async getUser(username) {
153153
const url = `/users?filter=handle%3D${username}`;
154154
const res = await this.private.api.get(url);
155-
return (await getApiResponsePayloadV3(res))[0];
155+
return (await getApiResponsePayload(res))[0];
156156
}
157157

158158
/**
@@ -166,7 +166,7 @@ class User {
166166
async getEmailPreferences(userId) {
167167
const url = `/users/${userId}/preferences/email`;
168168
const res = await this.private.api.get(url);
169-
return getApiResponsePayloadV3(res);
169+
return getApiResponsePayload(res);
170170
}
171171

172172
/**
@@ -193,7 +193,7 @@ class User {
193193
const url = `/users/${userId}/preferences/email`;
194194

195195
const res = await this.private.api.putJson(url, { param: settings });
196-
return getApiResponsePayloadV3(res);
196+
return getApiResponsePayload(res);
197197
}
198198

199199
/**
@@ -207,7 +207,7 @@ class User {
207207
async getCredential(userId) {
208208
const url = `/users/${userId}?fields=credential`;
209209
const res = await this.private.api.get(url);
210-
return getApiResponsePayloadV3(res);
210+
return getApiResponsePayload(res);
211211
}
212212

213213
/**
@@ -228,7 +228,7 @@ class User {
228228

229229
const url = `/users/${userId}`;
230230
const res = await this.private.api.patchJson(url, { param: { credential } });
231-
return getApiResponsePayloadV3(res);
231+
return getApiResponsePayload(res);
232232
}
233233

234234
/**
@@ -242,7 +242,7 @@ class User {
242242
async getLinkedAccounts(userId) {
243243
const url = `/users/${userId}?fields=profiles`;
244244
const res = await this.private.api.get(url);
245-
return getApiResponsePayloadV3(res);
245+
return getApiResponsePayload(res);
246246
}
247247

248248
/**
@@ -254,7 +254,7 @@ class User {
254254
async unlinkExternalAccount(userId, provider) {
255255
const url = `/users/${userId}/profiles/${provider}`;
256256
const res = await this.private.api.delete(url);
257-
return getApiResponsePayloadV3(res);
257+
return getApiResponsePayload(res);
258258
}
259259

260260
/**
@@ -299,7 +299,7 @@ class User {
299299
}
300300
logger.debug(`link API postdata: ${JSON.stringify(postData)}`);
301301
this.private.api.postJson(`/users/${userId}/profiles`, { param: postData })
302-
.then(resp => getApiResponsePayloadV3(resp).then((result) => {
302+
.then(resp => getApiResponsePayload(resp).then((result) => {
303303
logger.debug(`Succesfully linked account: ${JSON.stringify(result)}`);
304304
resolve(postData);
305305
}))

‎src/utils/tc.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export const REVIEW_OPPORTUNITY_TYPES = {
2626
};
2727

2828
/**
29-
* Gets payload from a standard success response from TC API v3; or throws
29+
* Gets payload from a standard success response from TC API; or throws
3030
* an error in case of a failure response.
3131
* @param {Object} res
3232
* @return {Promise} Resolves to the payload.
3333
*/
34-
export async function getApiResponsePayloadV3(res) {
34+
export async function getApiResponsePayload(res) {
3535
if (!res.ok) throw new Error(res.statusText);
3636
const x = (await res.json()).result;
3737
if (!x.success) throw new Error(x.content);
@@ -40,12 +40,12 @@ export async function getApiResponsePayloadV3(res) {
4040

4141

4242
/**
43-
* Gets payload from a standard success response from TC API v4; or throws
43+
* Gets payload from a standard success response from TC LOOKER API; or throws
4444
* an error in case of a failure response.
4545
* @param {Object} res
4646
* @return {Promise} Resolves to the payload.
4747
*/
48-
export async function getApiResponsePayloadV4(res) {
48+
export async function getLookerApiResponsePayload(res) {
4949
const resJson = await res.json();
5050
if (Array.isArray(resJson)) {
5151
return {

0 commit comments

Comments
 (0)
Please sign in to comment.