From e85b7d42d341a2a2cdb59bd94a96511022b054a7 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 15 Jun 2020 00:46:07 -0300 Subject: [PATCH 1/7] Fix group addMember call --- src/services/groups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/groups.js b/src/services/groups.js index 69603c0f..ecd6fda0 100644 --- a/src/services/groups.js +++ b/src/services/groups.js @@ -210,7 +210,7 @@ class GroupService { */ async addMember(groupId, memberId, membershipType) { const response = await this.private.api.postJson(`/groups/${groupId}/members`, { - param: { memberId, membershipType }, + memberId, membershipType, }); return handleApiResponse(response); From fc7ae1f10d67b329c2026f6b19d9f840d65418b5 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Tue, 16 Jun 2020 04:29:11 -0300 Subject: [PATCH 2/7] Updated loadProfileDone() to use V5 API --- src/actions/auth.js | 8 +++++--- src/services/groups.js | 4 ++-- src/utils/challenge/filter.js | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/actions/auth.js b/src/actions/auth.js index c585ec71..38f4f85f 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -16,12 +16,14 @@ import { getApi } from '../services/api'; function loadProfileDone(userTokenV3) { if (!userTokenV3) return Promise.resolve(null); const user = decodeToken(userTokenV3); - const api = getApi('V3', userTokenV3); + const api = getApi('V5', userTokenV3); return Promise.all([ api.get(`/members/${user.handle}`) - .then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : {})), + .then(res => (res.ok ? res.json() : new Error(res.statusText))) + .then(res => (res.message ? new Error(res.message) : res[0])), api.get(`/groups?memberId=${user.userId}&membershipType=user`) - .then(res => res.json()).then(res => (res.result.status === 200 ? res.result.content : [])), + .then(res => (res.ok ? res.json() : new Error(res.statusText))) + .then(res => (res.message ? new Error(res.message) : res)), ]).then(([profile, groups]) => ({ ...profile, groups })); } diff --git a/src/services/groups.js b/src/services/groups.js index ecd6fda0..a3b42a80 100644 --- a/src/services/groups.js +++ b/src/services/groups.js @@ -170,8 +170,8 @@ function mergeGroup(groups, group) { * @param {Object} group * @return {String[]} Array of IDs. */ -export function reduceGroupIds({ oldId, subGroups }) { - let res = [oldId]; +export function reduceGroupIds({ id, subGroups }) { + let res = [id]; if (subGroups) { subGroups.forEach((g) => { res = res.concat(reduceGroupIds(g)); diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index fcaf1924..0f8fac7f 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -382,7 +382,7 @@ export function mapToBackend(filter) { if (filter.or) return {}; const res = {}; - if (filter.groupIds) res.groupIds = filter.groupIds.join(','); + if (filter.groupIds) res.groupIds = filter.groupIds; // filter.groupIds.join(','); /* NOTE: Right now the frontend challenge filter by tag works different, * it looks for matches in the challenge name OR in the techs / platforms. */ From 606eb2e78085655d67cba562d87ee92dbc8e41d0 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Fri, 19 Jun 2020 11:01:42 -0300 Subject: [PATCH 3/7] Update Challenges param from groupIds to groups --- src/utils/challenge/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index 0f8fac7f..71f1d367 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -382,7 +382,7 @@ export function mapToBackend(filter) { if (filter.or) return {}; const res = {}; - if (filter.groupIds) res.groupIds = filter.groupIds; // filter.groupIds.join(','); + if (filter.groupIds) res.groups = filter.groupIds; /* NOTE: Right now the frontend challenge filter by tag works different, * it looks for matches in the challenge name OR in the techs / platforms. */ From ec7e414193d34a70283ed303f2a6331a3f05ec56 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Sat, 20 Jun 2020 16:19:58 -0300 Subject: [PATCH 4/7] Updated params groupIds to groups --- src/services/__mocks__/challenges.js | 8 ++++---- src/utils/challenge/filter.js | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/services/__mocks__/challenges.js b/src/services/__mocks__/challenges.js index 0dc59e7c..2c5e7ae4 100644 --- a/src/services/__mocks__/challenges.js +++ b/src/services/__mocks__/challenges.js @@ -85,8 +85,8 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username) // Fill missing data from v3_filtered if (v3Filtered) { const groups = {}; - if (v3Filtered.groupIds) { - v3Filtered.groupIds.forEach((id) => { + if (v3Filtered.groups) { + v3Filtered.groups.forEach((id) => { groups[id] = true; }); } @@ -165,8 +165,8 @@ export function normalizeChallengeDetails(v3, v3Filtered, v3User, v2, username) export function normalizeChallenge(challenge, username) { const registrationOpen = challenge.allPhases.filter(d => d.name === 'Registration')[0].isOpen ? 'Yes' : 'No'; const groups = {}; - if (challenge.groupIds) { - challenge.groupIds.forEach((id) => { + if (challenge.groups) { + challenge.groups.forEach((id) => { groups[id] = true; }); } diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index 80006db1..cf4cdd1e 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -18,7 +18,7 @@ * endDate {Number|String} - Permits only those challenges with submission * deadline before this date. * - * groupIds {Array} - Permits only the challenges belonging to at least one + * groups {Array} - Permits only the challenges belonging to at least one * of the groups which IDs are presented as keys in this object. * * or {Object[]} - All other filter fields applied to the challenge with AND @@ -71,8 +71,8 @@ import { COMPETITION_TRACKS, REVIEW_OPPORTUNITY_TYPES } from '../tc'; */ function filterByGroupIds(challenge, state) { - if (!state.groupIds) return true; - return state.groupIds.some(id => challenge.groups[id]); + if (!state.groups) return true; + return state.groups.some(id => challenge.groups[id]); } function filterByRegistrationOpen(challenge, state) { @@ -343,7 +343,7 @@ export function combine(...filters) { const res = {}; filters.forEach((filter) => { combineEndDate(res, filter); - combineArrayRules(res, filter, 'groupIds'); + combineArrayRules(res, filter, 'groups'); /* TODO: The registrationOpen rule is just ignored for now. */ combineStartDate(res, filter); combineArrayRules(res, filter, 'or', true); @@ -382,7 +382,7 @@ export function mapToBackend(filter) { if (filter.or) return {}; const res = {}; - if (filter.groupIds) res.groups = filter.groupIds; + if (filter.groups) res.groups = filter.groups; /* NOTE: Right now the frontend challenge filter by tag works different, * it looks for matches in the challenge name OR in the techs / platforms. */ From 0ae4e1e24b07cb469f9c89e60c5605d93a99b69c Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 22 Jun 2020 00:40:36 -0300 Subject: [PATCH 5/7] Fix challenges filter mapToBackend --- src/utils/challenge/filter.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/utils/challenge/filter.js b/src/utils/challenge/filter.js index cf4cdd1e..ca6de71d 100644 --- a/src/utils/challenge/filter.js +++ b/src/utils/challenge/filter.js @@ -379,15 +379,8 @@ export function combine(...filters) { * @return {Object} */ export function mapToBackend(filter) { - if (filter.or) return {}; - const res = {}; if (filter.groups) res.groups = filter.groups; - - /* NOTE: Right now the frontend challenge filter by tag works different, - * it looks for matches in the challenge name OR in the techs / platforms. */ - // if (filter.tags) res.technologies = filter.tags.join(','); - return res; } From 49ba5a12fb0973b97258e0ab8d9ec8389a7715e3 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 22 Jun 2020 11:34:55 -0300 Subject: [PATCH 6/7] Update auth tests to support v5 API --- __tests__/actions/auth.js | 11 +++++------ config/test.js | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/__tests__/actions/auth.js b/__tests__/actions/auth.js index eff03f17..2922e0b4 100644 --- a/__tests__/actions/auth.js +++ b/__tests__/actions/auth.js @@ -1,17 +1,16 @@ -const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v3/groups?memberId=12345&membershipType=user'; -const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v3/members/username12345'; +const MOCK_GROUPS_REQ_URL = 'https://api.topcoder-dev.com/v5/groups?memberId=12345&membershipType=user'; +const MOCK_PROFILE_REQ_URL = 'https://api.topcoder-dev.com/v5/members/username12345'; jest.mock('isomorphic-fetch', () => jest.fn(url => Promise.resolve({ + ok: true, json: () => { let content; switch (url) { case MOCK_GROUPS_REQ_URL: content = ['Group1', 'Group2']; break; - case MOCK_PROFILE_REQ_URL: content = { userId: 12345 }; break; + case MOCK_PROFILE_REQ_URL: content = [{ userId: 12345 }]; break; default: throw new Error('Unexpected URL!'); } - return { - result: { content, status: 200 }, - }; + return content; }, }))); diff --git a/config/test.js b/config/test.js index add8c31c..1d2ca856 100644 --- a/config/test.js +++ b/config/test.js @@ -2,6 +2,7 @@ module.exports = { API: { V2: 'https://api.topcoder-dev.com/v2', V3: 'https://api.topcoder-dev.com/v3', + V5: 'https://api.topcoder-dev.com/v5', }, dummyConfigKey: 'Dummy config value', SECRET: { From f3ea4dc2b004385d9cdf2c8092123583cffb6b46 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 22 Jun 2020 11:35:35 -0300 Subject: [PATCH 7/7] Fix auth description v3 to v5 --- src/actions/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/auth.js b/src/actions/auth.js index 38f4f85f..0a611f43 100644 --- a/src/actions/auth.js +++ b/src/actions/auth.js @@ -9,7 +9,7 @@ import { getApi } from '../services/api'; /** * @static - * @desc Creates an action that loads Topcoder user profile from v3 API. + * @desc Creates an action that loads Topcoder user profile from v5 API. * @param {String} userTokenV3 v3 authentication token. * @return {Action} */