Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 449473e

Browse files
committedOct 13, 2019
merge hot-fix to feature-my-challenges
2 parents 4ed73ab + 728f5fd commit 449473e

File tree

15 files changed

+1699
-717
lines changed

15 files changed

+1699
-717
lines changed
 

‎__tests__/__snapshots__/index.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Object {
5858
"getLookerDone": [Function],
5959
},
6060
"lookup": Object {
61+
"getAllCountriesDone": [Function],
62+
"getAllCountriesInit": [Function],
6163
"getCountriesDone": [Function],
6264
"getCountriesInit": [Function],
6365
"getSkillTagsDone": [Function],
@@ -318,10 +320,8 @@ Object {
318320
},
319321
},
320322
"submission": Object {
321-
"default": undefined,
322323
"getFinalScore": [Function],
323324
"getProvisionalScore": [Function],
324-
"processMMSubmissions": [Function],
325325
},
326326
"tc": Object {
327327
"COMPETITION_TRACKS": Object {

‎__tests__/actions/__snapshots__/lookup.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
exports[`Module exports 1`] = `
44
Object {
55
"lookup": Object {
6+
"getAllCountriesDone": [Function],
7+
"getAllCountriesInit": [Function],
68
"getCountriesDone": [Function],
79
"getCountriesInit": [Function],
810
"getSkillTagsDone": [Function],

‎__tests__/reducers/__snapshots__/lookup.js.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`Default reducer Get countries 1`] = `
44
Object {
5+
"allCountries": Array [],
56
"countries": Array [
67
Object {
78
"country": "Afghanistan",
@@ -23,6 +24,7 @@ Object {
2324

2425
exports[`Default reducer Get countries error 1`] = `
2526
Object {
27+
"allCountries": Array [],
2628
"countries": Array [
2729
Object {
2830
"country": "Afghanistan",
@@ -44,6 +46,7 @@ Object {
4446

4547
exports[`Default reducer Get skill tags 1`] = `
4648
Object {
49+
"allCountries": Array [],
4750
"countries": Array [],
4851
"loadingSkillTagsError": false,
4952
"skillTags": Array [
@@ -59,6 +62,7 @@ Object {
5962

6063
exports[`Default reducer Get skill tags error 1`] = `
6164
Object {
65+
"allCountries": Array [],
6266
"countries": Array [],
6367
"loadingSkillTagsError": true,
6468
"skillTags": Array [
@@ -74,13 +78,15 @@ Object {
7478

7579
exports[`Default reducer Initial state 1`] = `
7680
Object {
81+
"allCountries": Array [],
7782
"countries": Array [],
7883
"skillTags": Array [],
7984
}
8085
`;
8186

8287
exports[`Factory without server side rendering Get countries 1`] = `
8388
Object {
89+
"allCountries": Array [],
8490
"countries": Array [
8591
Object {
8692
"country": "Afghanistan",
@@ -102,6 +108,7 @@ Object {
102108

103109
exports[`Factory without server side rendering Get countries error 1`] = `
104110
Object {
111+
"allCountries": Array [],
105112
"countries": Array [
106113
Object {
107114
"country": "Afghanistan",
@@ -123,6 +130,7 @@ Object {
123130

124131
exports[`Factory without server side rendering Get skill tags 1`] = `
125132
Object {
133+
"allCountries": Array [],
126134
"countries": Array [],
127135
"loadingSkillTagsError": false,
128136
"skillTags": Array [
@@ -138,6 +146,7 @@ Object {
138146

139147
exports[`Factory without server side rendering Get skill tags error 1`] = `
140148
Object {
149+
"allCountries": Array [],
141150
"countries": Array [],
142151
"loadingSkillTagsError": true,
143152
"skillTags": Array [
@@ -153,6 +162,7 @@ Object {
153162

154163
exports[`Factory without server side rendering Initial state 1`] = `
155164
Object {
165+
"allCountries": Array [],
156166
"countries": Array [],
157167
"skillTags": Array [],
158168
}

‎docs/actions.lookup.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,34 @@ Actions related to lookup data.
99
* [.getSkillTagsDone()](#module_actions.lookup.getSkillTagsDone) ⇒ <code>Action</code>
1010
* [.getCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
1111
* [.getCountriesDone()](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
12+
* [.getAllCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
13+
* [.getAllCountriesDone(tokenV3)](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
1214

1315
<a name="module_actions.lookup.getSkillTagsInit"></a>
1416

1517
### actions.lookup.getSkillTagsInit() ⇒ <code>Action</code>
1618
Creates an action that signals beginning of getting all skill tags.
1719

18-
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
20+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
1921
<a name="module_actions.lookup.getSkillTagsDone"></a>
2022

2123
### actions.lookup.getSkillTagsDone() ⇒ <code>Action</code>
2224
Creates an action that gets all skill tags.
2325

24-
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
26+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
2527
<a name="module_actions.lookup.getCountriesDone"></a>
2628

2729
### actions.lookup.getCountriesDone() ⇒ <code>Action</code>
2830
Creates an action that gets all countries.
2931

30-
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
32+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
33+
<a name="module_actions.lookup.getCountriesDone"></a>
34+
35+
### actions.lookup.getAllCountriesDone(tokenV3) ⇒ <code>Action</code>
36+
Creates an action that gets all countries new version.
37+
38+
**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)
39+
40+
| Param | Type | Description |
41+
| --- | --- | --- |
42+
| tokenV3 | <code>String</code> | Topcoder v3 auth token. |

‎docs/services.members.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Gets member external account info.
114114

115115
| Param | Type |
116116
| --- | --- |
117-
| handle | <code>String</code> |
117+
| handle | <code>String</code> |
118118

119119
<a name="module_services.members..MembersService+getExternalLinks"></a>
120120

@@ -126,7 +126,7 @@ Gets member external links.
126126

127127
| Param | Type |
128128
| --- | --- |
129-
| handle | <code>String</code> |
129+
| handle | <code>String</code> |
130130

131131
<a name="module_services.members..MembersService+getSkills"></a>
132132

@@ -138,7 +138,7 @@ Gets member skills.
138138

139139
| Param | Type |
140140
| --- | --- |
141-
| handle | <code>String</code> |
141+
| handle | <code>String</code> |
142142

143143
<a name="module_services.members..MembersService+getStats"></a>
144144

@@ -150,7 +150,7 @@ Gets member statistics.
150150

151151
| Param | Type |
152152
| --- | --- |
153-
| handle | <code>String</code> |
153+
| handle | <code>String</code> |
154154

155155
<a name="module_services.members..MembersService+getStatsHistory"></a>
156156

@@ -162,7 +162,7 @@ Gets member statistics history
162162

163163
| Param | Type |
164164
| --- | --- |
165-
| handle | <code>String</code> |
165+
| handle | <code>String</code> |
166166

167167
<a name="module_services.members..MembersService+getStatsDistribution"></a>
168168

@@ -174,9 +174,9 @@ Gets member statistics distribution
174174

175175
| Param | Type |
176176
| --- | --- |
177-
| handle | <code>String</code> |
178-
| track | <code>String</code> |
179-
| subTrack | <code>String</code> |
177+
| handle | <code>String</code> |
178+
| track | <code>String</code> |
179+
| subTrack | <code>String</code> |
180180

181181
<a name="module_services.members..MembersService+getMemberSuggestions"></a>
182182

‎package-lock.json

Lines changed: 1548 additions & 486 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "0.8.0",
34+
"version": "0.8.2",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"config": "^3.2.0",

‎src/actions/challenge.js

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,12 @@
33
* @desc Actions related to Topcoder challenges APIs.
44
*/
55

6-
/* global CONFIG */
76
import _ from 'lodash';
87
import { config } from 'topcoder-react-utils';
98
import { createActions } from 'redux-actions';
109
import { getService as getChallengesService } from '../services/challenges';
1110
import { getService as getSubmissionService } from '../services/submissions';
12-
import { getService as getMemberService } from '../services/members';
1311
import { getApi } from '../services/api';
14-
import * as submissionUtil from '../utils/submission';
15-
16-
const { PAGE_SIZE } = CONFIG;
17-
18-
/**
19-
* Private. Loads from the backend all data matching some conditions.
20-
* @param {Function} getter Given params object of shape { limit, offset }
21-
* loads from the backend at most "limit" data, skipping the first
22-
* "offset" ones. Returns loaded data as an array.
23-
* @param {Number} page Optional. Next page of data to load.
24-
* @param {Number} perPage Optional. The size of the page content to load.
25-
* @param {Array} prev Optional. data loaded so far.
26-
*/
27-
function getAll(getter, page = 1, perPage = PAGE_SIZE, prev) {
28-
/* Amount of submissions to fetch in one API call. 50 is the current maximum
29-
* amount of submissions the backend returns, event when the larger limit is
30-
* explicitely required. */
31-
return getter({
32-
page,
33-
perPage,
34-
}).then((res) => {
35-
if (res.length === 0) {
36-
return prev || res;
37-
}
38-
// parse submissions
39-
let current = [];
40-
if (prev) {
41-
current = prev.concat(res);
42-
} else {
43-
current = res;
44-
}
45-
return getAll(getter, 1 + page, perPage, current);
46-
});
47-
}
4812

4913
/**
5014
* @static
@@ -142,26 +106,10 @@ function getMMSubmissionsInit(challengeId) {
142106
* @param {String} tokenV3 Topcoder auth token v3.
143107
* @return {Action}
144108
*/
145-
function getMMSubmissionsDone(challengeId, registrants, tokenV3) {
146-
const filter = { challengeId };
147-
const memberService = getMemberService(tokenV3);
109+
async function getMMSubmissionsDone(challengeId, registrants, tokenV3) {
148110
const submissionsService = getSubmissionService(tokenV3);
149-
150-
// TODO: Move those numbers to configs
151-
return getAll(params => submissionsService.getSubmissions(filter, params), 1, 500)
152-
.then((submissions) => {
153-
const userIds = _.uniq(_.map(submissions, sub => sub.memberId));
154-
return memberService.getMembersInformation(userIds)
155-
.then((resources) => {
156-
const finalSubmissions = submissionUtil
157-
.processMMSubmissions(submissions, resources, registrants);
158-
return {
159-
challengeId,
160-
submissions: finalSubmissions,
161-
tokenV3,
162-
};
163-
});
164-
});
111+
const submissions = await submissionsService.getSubmissions(challengeId);
112+
return { challengeId, submissions, tokenV3 };
165113
}
166114

167115
/**

‎src/actions/lookup.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,30 @@ function getCountriesDone() {
4242
return getService().getCountries();
4343
}
4444

45+
/**
46+
* @static
47+
* @desc Creates an action that signals beginning of getting all countries api version 5.
48+
* @return {Action}
49+
*/
50+
function getAllCountriesInit() {}
51+
52+
/**
53+
* @static
54+
* @desc Creates an action that gets all countries api version 5.
55+
* @param {String} tokenV3 Optional. Auth token for Topcoder API v3.
56+
* @return {Action}
57+
*/
58+
function getAllCountriesDone(tokenV3) {
59+
return getService(tokenV3).getAllCountries();
60+
}
61+
4562
export default createActions({
4663
LOOKUP: {
4764
GET_SKILL_TAGS_INIT: getSkillTagsInit,
4865
GET_SKILL_TAGS_DONE: getSkillTagsDone,
4966
GET_COUNTRIES_INIT: getCountriesInit,
5067
GET_COUNTRIES_DONE: getCountriesDone,
68+
GET_ALL_COUNTRIES_INIT: getAllCountriesInit,
69+
GET_ALL_COUNTRIES_DONE: getAllCountriesDone,
5170
},
5271
});

‎src/reducers/lookup.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ function onGetCountriesDone(state, { payload, error }) {
4848
});
4949
}
5050

51+
/**
52+
* Handles LOOKUP/GET_ALL_COUNTRIES_DONE action.
53+
* @param {Object} state
54+
* @param {Object} action Payload will be JSON from api call
55+
* @return {Object} New state
56+
*/
57+
function onGetAllCountriesDone(state, { payload, error }) {
58+
if (error) {
59+
logger.error('Failed to get all countries', payload);
60+
return { ...state, loadingAllCountriesError: true };
61+
}
62+
63+
return ({
64+
...state,
65+
loadingAllCountriesError: false,
66+
allCountries: payload,
67+
});
68+
}
69+
5170
/**
5271
* Creates a new Lookup reducer with the specified initial state.
5372
* @param {Object} initialState Optional. Initial state.
@@ -60,9 +79,12 @@ function create(initialState = {}) {
6079
[a.getSkillTagsDone]: onGetSkillTagsDone,
6180
[a.getCountriesInit]: state => state,
6281
[a.getCountriesDone]: onGetCountriesDone,
82+
[a.getAllCountriesInit]: state => state,
83+
[a.getAllCountriesDone]: onGetAllCountriesDone,
6384
}, _.defaults(initialState, {
6485
skillTags: [],
6586
countries: [],
87+
allCountries: [],
6688
}));
6789
}
6890

‎src/services/challenges.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import logger from '../utils/logger';
1212
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
1313
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
1414
import { getApi } from './api';
15+
import { getService as getMembersService } from './members';
1516

1617
export const ORDER_BY = {
1718
SUBMISSION_END_DATE: 'submissionEndDate',
@@ -263,6 +264,7 @@ class ChallengesService {
263264
getChallenges,
264265
tokenV2,
265266
tokenV3,
267+
memberService: getMembersService(),
266268
};
267269
}
268270

@@ -386,6 +388,17 @@ class ChallengesService {
386388
return finalChallenge;
387389
}
388390

391+
/**
392+
* Gets challenge registrants from Topcoder API.
393+
* @param {Number|String} challengeId
394+
* @return {Promise} Resolves to the challenge registrants array.
395+
*/
396+
async getChallengeRegistrants(challengeId) {
397+
const challenge = await this.private.api.get(`/challenges/${challengeId}`)
398+
.then(checkError).then(res => res.content);
399+
return challenge.registrants;
400+
}
401+
389402
/**
390403
* Gets possible challenge subtracks.
391404
* @return {Promise} Resolves to the array of subtrack names.
@@ -480,7 +493,6 @@ class ChallengesService {
480493
return this.private.getChallenges(endpoint, filters, params);
481494
}
482495

483-
484496
/**
485497
* Gets SRM matches related to the user.
486498
* @param {String} handle
@@ -590,6 +602,26 @@ class ChallengesService {
590602
if (res.status !== 200) throw new Error(res.content);
591603
return res.content;
592604
}
605+
606+
/**
607+
* Gets roles of a user in the specified challenge. The user tested is
608+
* the owner of authentication token used to instantiate the service.
609+
*
610+
* Notice, if you have already loaded the challenge as that user, these roles
611+
* are attached to the challenge object under `userDetails.roles` path during
612+
* challenge normalization. However, if you have not, this method is the most
613+
* efficient way to get them, as it by-passes any unnecessary normalizations
614+
* of the challenge object.
615+
*
616+
* @param {Number} challengeId Challenge ID.
617+
*/
618+
async getUserRolesInChallenge(challengeId) {
619+
const user = decodeToken(this.private.tokenV3);
620+
const username = user.handle || user.payload.handle;
621+
const url = `/members/${username.toLowerCase()}/challenges`;
622+
const data = await this.private.getChallenges(url, { id: challengeId });
623+
return data.challenges[0].userDetails.roles;
624+
}
593625
}
594626

595627
let lastInstance = null;

‎src/services/lookup.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class LookupService {
1414
constructor(tokenV3) {
1515
this.private = {
1616
api: getApi('V3', tokenV3),
17+
apiV5: getApi('V5', tokenV3),
1718
tokenV3,
1819
};
1920
}
@@ -37,6 +38,16 @@ class LookupService {
3738
const res = await this.private.api.get('/members/lookup/countries');
3839
return getApiResponsePayload(res);
3940
}
41+
42+
/**
43+
* Gets all countries.
44+
* @return {Promise} Resolves to the countries.
45+
*/
46+
async getAllCountries() {
47+
const res = await this.private.apiV5.get('/lookups/countries');
48+
const jsonResult = await res.json();
49+
return jsonResult;
50+
}
4051
}
4152

4253
let lastInstance = null;

‎src/services/submissions.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Topcoder submissions via TC API. Currently only used for MM challenges
55
*/
66

7-
import qs from 'qs';
87
import { getApi } from './api';
98

109
/**
@@ -17,26 +16,20 @@ class SubmissionsService {
1716
*/
1817
constructor(tokenV3) {
1918
this.private = {
20-
apiV5: getApi('V5', tokenV3),
19+
broker: getApi('MM_BROKER', tokenV3),
2120
tokenV3,
2221
};
2322
}
2423

2524
/**
2625
* Get submissions of challenge
27-
* @param {Object} filters
28-
* @param {Object} params
26+
* @param {Object} challengeId
2927
* @return {Promise} Resolves to the api response.
3028
*/
31-
async getSubmissions(filters, params) {
32-
const query = {
33-
...filters,
34-
...params,
35-
};
36-
const url = `/submissions?${qs.stringify(query, { encode: false })}`;
37-
return this.private.apiV5.get(url)
38-
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
39-
.then(res => res);
29+
async getSubmissions(challengeId) {
30+
const url = `/v5/submissions?challengeId=${challengeId}`;
31+
return this.private.broker.get(url)
32+
.then(res => (res.ok ? res.json() : new Error(res.statusText)));
4033
}
4134

4235
/**
@@ -45,10 +38,9 @@ class SubmissionsService {
4538
* @returns {Promise} Resolves to the api response.
4639
*/
4740
async getSubmissionInformation(submissionId) {
48-
const url = `/submissions/${submissionId}`;
49-
return this.private.apiV5.get(url)
50-
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
51-
.then(res => res);
41+
const url = `/v5/submissions/${submissionId}`;
42+
return this.private.broker.get(url)
43+
.then(res => (res.ok ? res.json() : new Error(res.statusText)));
5244
}
5345
}
5446

‎src/utils/submission.js

Lines changed: 0 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,6 @@
11
/**
22
* Various submissions functions.
33
*/
4-
/* global CONFIG */
5-
/* eslint-disable no-param-reassign */
6-
import _ from 'lodash';
7-
8-
const { AV_SCAN_SCORER_REVIEW_TYPE_ID } = CONFIG;
9-
10-
function removeDecimal(num) {
11-
const re = new RegExp('^-?\\d+');
12-
return num.toString().match(re)[0];
13-
}
14-
15-
function toAcurateFixed(num, decimal) {
16-
const re = new RegExp(`^-?\\d+(?:.\\d{0,${(decimal)}})?`);
17-
return num.toString().match(re)[0];
18-
}
19-
20-
function toFixed(num, decimal) {
21-
if (_.isNaN(parseFloat(num))) return num;
22-
num = parseFloat(num);
23-
24-
const result = _.toFinite(toAcurateFixed(num, decimal));
25-
const integerResult = _.toFinite(removeDecimal(num));
26-
27-
if (_.isInteger(result)) {
28-
return integerResult;
29-
}
30-
return result;
31-
}
32-
33-
function getMMChallengeHandleStyle(handle, registrants) {
34-
const style = _.get(_.find(registrants, m => m.handle === handle), 'colorStyle', null);
35-
if (style) return JSON.parse(style.replace(/(\w+):\s*([^;]*)/g, '{"$1": "$2"}'));
36-
return {};
37-
}
38-
39-
/**
40-
* Process each submission rank of MM challenge
41-
* @param submissions the array of submissions
42-
*/
43-
function processRanks(submissions) {
44-
let maxFinalScore = 0;
45-
submissions.sort((a, b) => {
46-
let pA = _.get(a, 'submissions[0]', { provisionalScore: 0 }).provisionalScore;
47-
let pB = _.get(b, 'submissions[0]', { provisionalScore: 0 }).provisionalScore;
48-
if (pA === '-') pA = 0;
49-
if (pB === '-') pB = 0;
50-
if (pA === pB) {
51-
const timeA = new Date(_.get(a, 'submissions[0].submissionTime'));
52-
const timeB = new Date(_.get(b, 'submissions[0].submissionTime'));
53-
return timeA - timeB;
54-
}
55-
return pB - pA;
56-
});
57-
_.each(submissions, (submission, i) => {
58-
submissions[i].provisionalRank = i + 1;
59-
});
60-
61-
submissions.sort((a, b) => {
62-
let pA = _.get(a, 'submissions[0]', { finalScore: 0 }).finalScore;
63-
let pB = _.get(b, 'submissions[0]', { finalScore: 0 }).finalScore;
64-
if (pA === '-') pA = 0;
65-
if (pB === '-') pB = 0;
66-
if (pA > 0) maxFinalScore = pA;
67-
if (pB > 0) maxFinalScore = pB;
68-
if (pA === pB) {
69-
const timeA = new Date(_.get(a, 'submissions[0].submissionTime'));
70-
const timeB = new Date(_.get(b, 'submissions[0].submissionTime'));
71-
return timeA - timeB;
72-
}
73-
return pB - pA;
74-
});
75-
if (maxFinalScore > 0) {
76-
_.each(submissions, (submission, i) => {
77-
submissions[i].finalRank = i + 1;
78-
});
79-
}
80-
return { submissions, maxFinalScore };
81-
}
824

835
/**
846
* Get provisional score of submission
@@ -111,66 +33,3 @@ export function getFinalScore(submission) {
11133
}
11234
return finalScore;
11335
}
114-
115-
/**
116-
* Process submissions of MM challenge
117-
* @param submissions the array of submissions
118-
* @param resources the challenge resources
119-
* @param registrants the challenge registrants
120-
*/
121-
export function processMMSubmissions(submissions, resources, registrants) {
122-
const data = {};
123-
const result = [];
124-
125-
_.each(submissions, (submission) => {
126-
const { memberId } = submission;
127-
let memberHandle;
128-
const resource = _.find(resources, r => _.get(r, 'userId').toString() === memberId.toString());
129-
if (_.isEmpty(resource)) {
130-
memberHandle = memberId;
131-
} else {
132-
memberHandle = _.has(resource, 'handle') ? _.get(resource, 'handle') : memberId.toString();
133-
}
134-
if (!data[memberHandle]) {
135-
data[memberHandle] = [];
136-
}
137-
const validReviews = _.filter(submission.review,
138-
r => !_.isEmpty(r) && (r.typeId !== AV_SCAN_SCORER_REVIEW_TYPE_ID));
139-
validReviews.sort((a, b) => {
140-
const dateA = new Date(a.created);
141-
const dateB = new Date(b.created);
142-
return dateB - dateA;
143-
});
144-
145-
const provisionalScore = toFixed(_.get(validReviews, '[0].score', '-'), 5);
146-
const finalScore = toFixed(_.get(submission, 'reviewSummation[0].aggregateScore', '-'), 5);
147-
148-
data[memberHandle].push({
149-
submissionId: submission.id,
150-
submissionTime: submission.created,
151-
provisionalScore,
152-
finalScore,
153-
});
154-
});
155-
156-
_.each(data, (value, key) => {
157-
result.push({
158-
submissions: [...value.sort((a, b) => new Date(b.submissionTime)
159-
.getTime() - new Date(a.submissionTime).getTime())],
160-
member: key,
161-
colorStyle: getMMChallengeHandleStyle(key, registrants),
162-
});
163-
});
164-
165-
const { submissions: finalSubmissions, maxFinalScore } = processRanks(result);
166-
finalSubmissions.sort((a, b) => {
167-
if (maxFinalScore === 0) {
168-
return a.provisionalRank - b.provisionalRank;
169-
}
170-
return a.finalRank - b.finalRank;
171-
});
172-
173-
return finalSubmissions;
174-
}
175-
176-
export default undefined;

‎src/utils/tc.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,25 @@ export const REVIEW_OPPORTUNITY_TYPES = {
2929
* 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
32+
* @param {Boolean} shouldThrowError should throw error if request fail
3233
* @return {Promise} Resolves to the payload.
3334
*/
34-
export async function getApiResponsePayload(res) {
35-
if (!res.ok) throw new Error(res.statusText);
35+
export async function getApiResponsePayload(res, shouldThrowError = true) {
36+
if (!res.ok) {
37+
if (shouldThrowError) {
38+
throw new Error(res.statusText);
39+
} else {
40+
return null;
41+
}
42+
}
3643
const x = (await res.json()).result;
37-
if (!x.success) throw new Error(x.content);
44+
if ((!x.success)) {
45+
if (shouldThrowError) {
46+
throw new Error(x.content);
47+
} else {
48+
return null;
49+
}
50+
}
3851
return x.content;
3952
}
4053

0 commit comments

Comments
 (0)
Please sign in to comment.