Skip to content

Release 2020/11/10 - Stats History API V4 #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a55ed40
support for job descriptions
skyhit Sep 27, 2020
711dd9d
fix for feedback
skyhit Oct 3, 2020
a0abad7
fix tests
skyhit Oct 7, 2020
ba1079f
fix; for issue #4659
luizrrodrigues Oct 13, 2020
3faff6b
ci: added dist tag
luizrrodrigues Oct 13, 2020
48b9d26
patch: use v4 api to get member stats history
gets0ul Oct 27, 2020
77c3499
Merge pull request #276 from gets0ul/use_v4_for_stats_history
luizrrodrigues Nov 3, 2020
1051c21
fix: for issue #4527
luizrrodrigues Nov 4, 2020
e0ef678
fix: for issue #4659
luizrrodrigues Nov 9, 2020
ed85b7d
Merge branch 'develop' into support_for_job_description
luizrrodrigues Nov 9, 2020
fa269f9
fix: for issue #4659 sync with develop
luizrrodrigues Nov 9, 2020
8ed3365
LookupService - Call v4 api /technologies instead v3
luizrrodrigues Nov 9, 2020
23f25b2
Merge branch 'develop' into stats-history-v4
luizrrodrigues Nov 10, 2020
8180149
Merge pull request #281 from topcoder-platform/stats-history-v4
luizrrodrigues Nov 10, 2020
3b8c6bd
ci: added dist tag
luizrrodrigues Nov 10, 2020
0f90892
Merge branch 'develop' into support_for_job_description
luizrrodrigues Nov 10, 2020
1909681
Merge pull request #261 from topcoder-platform/support_for_job_descri…
luizrrodrigues Nov 10, 2020
5aa0fdf
Revert "support for job descriptions"
luizrrodrigues Nov 10, 2020
c61e457
Merge pull request #282 from topcoder-platform/revert-261-support_for…
luizrrodrigues Nov 10, 2020
bf88ec4
ci: removed dist tag
luizrrodrigues Nov 10, 2020
7512db6
fix; for issue #4527
luizrrodrigues Nov 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1.1.1",
"version": "1.1.2",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
78 changes: 76 additions & 2 deletions src/actions/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down