Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: topcoder-platform/topcoder-react-lib
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1000.25.5
Choose a base ref
...
head repository: topcoder-platform/topcoder-react-lib
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: support_for_job_description
Choose a head ref
  • 8 commits
  • 4 files changed
  • 2 contributors

Commits on Oct 27, 2020

  1. Copy the full SHA
    48b9d26 View commit details

Commits on Nov 3, 2020

  1. Merge pull request #276 from gets0ul/use_v4_for_stats_history

    patch: use v4 api to get member stats history
    luizrrodrigues authored Nov 3, 2020
    Copy the full SHA
    77c3499 View commit details

Commits on Nov 4, 2020

  1. Copy the full SHA
    1051c21 View commit details

Commits on Nov 9, 2020

  1. Copy the full SHA
    8ed3365 View commit details

Commits on Nov 10, 2020

  1. Copy the full SHA
    23f25b2 View commit details
  2. Merge pull request #281 from topcoder-platform/stats-history-v4

    Smoke Testing 2020/11/10 - Stats history v4
    luizrrodrigues authored Nov 10, 2020
    Copy the full SHA
    8180149 View commit details
  3. ci: added dist tag

    luizrrodrigues authored Nov 10, 2020
    Copy the full SHA
    3b8c6bd View commit details
  4. Copy the full SHA
    0f90892 View commit details
Showing with 98 additions and 4 deletions.
  1. +1 −1 package.json
  2. +76 −2 src/actions/members.js
  3. +19 −0 src/services/challenges.js
  4. +2 −1 src/services/lookup.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1000.25.5",
"version": "1000.25.8",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
78 changes: 76 additions & 2 deletions src/actions/members.js
Original file line number Diff line number Diff line change
@@ -143,6 +143,7 @@ async function getActiveChallengesInit(handle, uuid) {
* @param {String} tokenV3
* @returns {Object} Payload
*/
/* eslint-disable no-unused-vars */
async function getActiveChallengesDone(handle, uuid, tokenV3) {
const filter = { status: 'Active' };
const service = getChallengesService(tokenV3);
@@ -168,6 +169,38 @@ async function getActiveChallengesDone(handle, uuid, tokenV3) {

return { handle, challenges, uuid };
}
/* eslint-enable no-unused-vars */

/**
* @static
* @desc Payload creator for the action that loads the member active challenges from v4 api.
* @param {String} handle
* @param {String} uuid
* @param {String} tokenV3
* @returns {Object} Payload
*/
async function getActiveChallengesV4Done(handle, uuid, tokenV3) {
const filter = { status: 'Active' };
const service = getChallengesService(tokenV3);

function getAll(getter, page = 0, prev = null) {
const PAGE_SIZE = 50;
return getter({
limit: PAGE_SIZE,
offset: page * PAGE_SIZE,
}).then(({ challenges: chunk }) => {
if (!chunk.length) return prev || [];
return getAll(getter, 1 + page, prev ? prev.concat(chunk) : chunk);
});
}
const calls = [
getAll(params => service.getUserChallengesV4(handle, filter, params)),
];

const [challenges] = await Promise.all(calls);

return { handle, challenges, uuid };
}

/**
* @static
@@ -243,6 +276,7 @@ async function getSubtrackChallengesInit(handle, uuid) {
* @param {Boolean} whether to refresh.
* @return {Action}
*/
/* eslint-disable no-unused-vars */
async function getSubtrackChallengesDone(
uuid, handle, tokenV3, track, subTrack, pageNum, pageSize,
refresh, userId,
@@ -268,6 +302,46 @@ async function getSubtrackChallengesDone(
handle,
}));
}
/* eslint-enable no-unused-vars */

/**
* @static
* @desc Create an action that loads the member subtrack challenges from v4 api.
* @param {String} uuid Operation UUID.
* @param {String} handle Member handle.
* @param {String} tokenV3 v3 auth token.
* @param {String} track Main track name.
* @param {String} subTrack Subtrack name.
* @param {Number} start page.
* @param {Number} page size.
* @param {Boolean} whether to refresh.
* @return {Action}
*/
async function getSubtrackChallengesV4Done(
uuid, handle, tokenV3, track, subTrack, pageNum, pageSize,
refresh,
) {
const filter = {
status: 'Completed',
hasUserSubmittedForReview: 'true',
track,
subTrack,
};

const params = {};
params.orderBy = 'submissionEndDate desc';
params.limit = pageSize;
params.offset = (pageNum - 1) * pageSize; // pageNum - 1 to match with v4 offset

const service = getChallengesService(tokenV3);
return service.getUserChallengesV4(handle, filter, params)
.then(res => ({
uuid,
challenges: res.challenges,
refresh,
handle,
}));
}

/**
* @static
@@ -399,9 +473,9 @@ export default createActions({
GET_STATS_DISTRIBUTION_INIT: getStatsDistributionInit,
GET_STATS_DISTRIBUTION_DONE: getStatsDistributionDone,
GET_ACTIVE_CHALLENGES_INIT: getActiveChallengesInit,
GET_ACTIVE_CHALLENGES_DONE: getActiveChallengesDone,
GET_ACTIVE_CHALLENGES_DONE: getActiveChallengesV4Done,
GET_SUBTRACK_CHALLENGES_INIT: getSubtrackChallengesInit,
GET_SUBTRACK_CHALLENGES_DONE: getSubtrackChallengesDone,
GET_SUBTRACK_CHALLENGES_DONE: getSubtrackChallengesV4Done,
GET_USER_SRM_INIT: getUserSRMInit,
GET_USER_SRM_DONE: getUserSRMDone,
GET_USER_MARATHON_INIT: getUserMarathonInit,
19 changes: 19 additions & 0 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
@@ -572,6 +572,25 @@ class ChallengesService {
};
}

/**
* Gets challenges of the specified user from v4 api.
* @param {String} username User name whose challenges we want to fetch.
* @return {Promise} Resolves to the api response.
*/
async getUserChallengesV4(username, filters, params) {
const endpoint = `/members/${username.toLowerCase()}/challenges/`;
const query = {
filter: qs.stringify(filters, { encode: false }),
...params,
};
const url = `${endpoint}?${qs.stringify(query)}`;
const res = await this.private.api.get(url).then(checkError);
return {
challenges: res.content || [],
totalCount: res.metadata.totalCount,
};
}

/**
* Gets user resources.
* @param {String} userId User id whose challenges we want to fetch.
3 changes: 2 additions & 1 deletion src/services/lookup.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ class LookupService {
constructor(tokenV3) {
this.private = {
api: getApi('V3', tokenV3),
apiV4: getApi('V4', tokenV3),
apiV5: getApi('V5', tokenV3),
tokenV3,
};
@@ -125,7 +126,7 @@ class LookupService {
* @return {Promise} Resolves to the review types.
*/
async getTechnologies() {
const res = await this.private.api.get('/technologies');
const res = await this.private.apiV4.get('/technologies');
return getApiResponsePayload(res);
}
}