Skip to content

Commit 8d763fc

Browse files
authored
Merge pull request #194 from topcoder-platform/issue-4393
Issue 4393 - Challenge Listings: Challenges not loading for subcommunities
2 parents 03713ef + f3ea4dc commit 8d763fc

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

__tests__/actions/auth.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v3/groups?memberId=12345&membershipType=user';
2-
const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v3/members/username12345';
1+
const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v5/groups?memberId=12345&membershipType=user';
2+
const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v5/members/username12345';
33

44
jest.mock('isomorphic-fetch', () => jest.fn(url => Promise.resolve({
5+
ok: true,
56
json: () => {
67
let content;
78
switch (url) {
89
case MOCK_GROUPS_REQ_URL: content = ['Group1', 'Group2']; break;
9-
case MOCK_PROFILE_REQ_URL: content = { userId: 12345 }; break;
10+
case MOCK_PROFILE_REQ_URL: content = [{ userId: 12345 }]; break;
1011
default: throw new Error('Unexpected URL!');
1112
}
12-
return {
13-
result: { content, status: 200 },
14-
};
13+
return content;
1514
},
1615
})));
1716

config/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
API: {
33
V2: 'https://api.topcoder-dev.com/v2',
44
V3: 'https://api.topcoder-dev.com/v3',
5+
V5: 'https://api.topcoder-dev.com/v5',
56
},
67
dummyConfigKey: 'Dummy config value',
78
SECRET: {

src/actions/auth.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ import { getApi } from '../services/api';
99

1010
/**
1111
* @static
12-
* @desc Creates an action that loads Topcoder user profile from v3 API.
12+
* @desc Creates an action that loads Topcoder user profile from v5 API.
1313
* @param {String} userTokenV3 v3 authentication token.
1414
* @return {Action}
1515
*/
1616
function loadProfileDone(userTokenV3) {
1717
if (!userTokenV3) return Promise.resolve(null);
1818
const user = decodeToken(userTokenV3);
19-
const api = getApi('V3', userTokenV3);
19+
const api = getApi('V5', userTokenV3);
2020
return Promise.all([
2121
api.get(`/members/${user.handle}`)
22-
.then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})),
22+
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
23+
.then(res => (res.message ? new Error(res.message) : res[0])),
2324
api.get(`/groups?memberId=${user.userId}&membershipType=user`)
24-
.then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : [])),
25+
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
26+
.then(res => (res.message ? new Error(res.message) : res)),
2527
]).then(([profile, groups]) => ({ ...profile, groups }));
2628
}
2729

src/services/__mocks__/challenges.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username)
8585
// Fill missing data from v3_filtered
8686
if (v3Filtered) {
8787
const groups = {};
88-
if (v3Filtered.groupIds) {
89-
v3Filtered.groupIds.forEach((id) => {
88+
if (v3Filtered.groups) {
89+
v3Filtered.groups.forEach((id) => {
9090
groups[id] = true;
9191
});
9292
}
@@ -165,8 +165,8 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username)
165165
export function normalizeChallenge(challenge, username) {
166166
const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isOpen ? 'Yes' : 'No';
167167
const groups = {};
168-
if (challenge.groupIds) {
169-
challenge.groupIds.forEach((id) => {
168+
if (challenge.groups) {
169+
challenge.groups.forEach((id) => {
170170
groups[id] = true;
171171
});
172172
}

src/services/groups.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ function mergeGroup(groups, group) {
170170
* @param {Object} group
171171
* @return {String[]} Array of IDs.
172172
*/
173-
export function reduceGroupIds({ oldId, subGroups }) {
174-
let res = [oldId];
173+
export function reduceGroupIds({ id, subGroups }) {
174+
let res = [id];
175175
if (subGroups) {
176176
subGroups.forEach((g) => {
177177
res = res.concat(reduceGroupIds(g));
@@ -210,7 +210,7 @@ class GroupService {
210210
*/
211211
async addMember(groupId, memberId, membershipType) {
212212
const response = await this.private.api.postJson(`/groups/${groupId}/members`, {
213-
param: { memberId, membershipType },
213+
memberId, membershipType,
214214
});
215215

216216
return handleApiResponse(response);

src/utils/challenge/filter.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* endDate {Number|String} - Permits only those challenges with submission
1919
* deadline before this date.
2020
*
21-
* groupIds {Array} - Permits only the challenges belonging to at least one
21+
* groups {Array} - Permits only the challenges belonging to at least one
2222
* of the groups which IDs are presented as keys in this object.
2323
*
2424
* or {Object[]} - All other filter fields applied to the challenge with AND
@@ -71,8 +71,8 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc';
7171
*/
7272

7373
function filterByGroupIds(challenge, state) {
74-
if (!state.groupIds) return true;
75-
return state.groupIds.some(id => challenge.groups[id]);
74+
if (!state.groups) return true;
75+
return state.groups.some(id => challenge.groups[id]);
7676
}
7777

7878
function filterByRegistrationOpen(challenge, state) {
@@ -343,7 +343,7 @@ export function combine(...filters) {
343343
const res = {};
344344
filters.forEach((filter) => {
345345
combineEndDate(res, filter);
346-
combineArrayRules(res, filter, 'groupIds');
346+
combineArrayRules(res, filter, 'groups');
347347
/* TODO: The registrationOpen rule is just ignored for now. */
348348
combineStartDate(res, filter);
349349
combineArrayRules(res, filter, 'or', true);
@@ -379,15 +379,8 @@ export function combine(...filters) {
379379
* @return {Object}
380380
*/
381381
export function mapToBackend(filter) {
382-
if (filter.or) return {};
383-
384382
const res = {};
385-
if (filter.groupIds) res.groupIds = filter.groupIds.join(',');
386-
387-
/* NOTE: Right now the frontend challenge filter by tag works different,
388-
* it looks for matches in the challenge name OR in the techs / platforms. */
389-
// if (filter.tags) res.technologies = filter.tags.join(',');
390-
383+
if (filter.groups) res.groups = filter.groups;
391384
return res;
392385
}
393386

0 commit comments

Comments
 (0)