Skip to content

Feature sort registrations #99

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 5 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Fix for issue #3351
  • Loading branch information
codeMinter committed Oct 9, 2019
commit 0be139e4f659a4c554e6f6aa0ce0be4ff40dbe9a
2 changes: 2 additions & 0 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Object {
"getLookerDone": [Function],
},
"lookup": Object {
"getAllCountriesDone": [Function],
"getAllCountriesInit": [Function],
"getCountriesDone": [Function],
"getCountriesInit": [Function],
"getSkillTagsDone": [Function],
Expand Down
2 changes: 2 additions & 0 deletions __tests__/actions/__snapshots__/lookup.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
exports[`Module exports 1`] = `
Object {
"lookup": Object {
"getAllCountriesDone": [Function],
"getAllCountriesInit": [Function],
"getCountriesDone": [Function],
"getCountriesInit": [Function],
"getSkillTagsDone": [Function],
Expand Down
10 changes: 10 additions & 0 deletions __tests__/reducers/__snapshots__/lookup.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`Default reducer Get countries 1`] = `
Object {
"allCountries": Array [],
"countries": Array [
Object {
"country": "Afghanistan",
Expand All @@ -23,6 +24,7 @@ Object {

exports[`Default reducer Get countries error 1`] = `
Object {
"allCountries": Array [],
"countries": Array [
Object {
"country": "Afghanistan",
Expand All @@ -44,6 +46,7 @@ Object {

exports[`Default reducer Get skill tags 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": false,
"skillTags": Array [
Expand All @@ -59,6 +62,7 @@ Object {

exports[`Default reducer Get skill tags error 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": true,
"skillTags": Array [
Expand All @@ -74,13 +78,15 @@ Object {

exports[`Default reducer Initial state 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"skillTags": Array [],
}
`;

exports[`Factory without server side rendering Get countries 1`] = `
Object {
"allCountries": Array [],
"countries": Array [
Object {
"country": "Afghanistan",
Expand All @@ -102,6 +108,7 @@ Object {

exports[`Factory without server side rendering Get countries error 1`] = `
Object {
"allCountries": Array [],
"countries": Array [
Object {
"country": "Afghanistan",
Expand All @@ -123,6 +130,7 @@ Object {

exports[`Factory without server side rendering Get skill tags 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": false,
"skillTags": Array [
Expand All @@ -138,6 +146,7 @@ Object {

exports[`Factory without server side rendering Get skill tags error 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"loadingSkillTagsError": true,
"skillTags": Array [
Expand All @@ -153,6 +162,7 @@ Object {

exports[`Factory without server side rendering Initial state 1`] = `
Object {
"allCountries": Array [],
"countries": Array [],
"skillTags": Array [],
}
Expand Down
114 changes: 57 additions & 57 deletions dist/dev/index.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions docs/actions.lookup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,34 @@ Actions related to lookup data.
* [.getSkillTagsDone()](#module_actions.lookup.getSkillTagsDone) ⇒ <code>Action</code>
* [.getCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
* [.getCountriesDone()](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>
* [.getAllCountriesInit()](#module_actions.lookup.getCountriesInit) ⇒ <code>Action</code>
* [.getAllCountriesDone(tokenV3)](#module_actions.lookup.getCountriesDone) ⇒ <code>Action</code>

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

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

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

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

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

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

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

### actions.lookup.getAllCountriesDone(tokenV3) ⇒ <code>Action</code>
Creates an action that gets all countries new version.

**Kind**: static method of [<code>actions.lookup</code>](#module_actions.lookup)

| Param | Type | Description |
| --- | --- | --- |
| tokenV3 | <code>String</code> | Topcoder v3 auth token. |
30 changes: 22 additions & 8 deletions docs/services.members.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members via API V3.
* [new MembersService(tokenV3)](#new_module_services.members..MembersService_new)
* [.getMemberFinances(handle)](#module_services.members..MembersService+getMemberFinances) ⇒ <code>Promise</code>
* [.getMemberInfo(handle)](#module_services.members..MembersService+getMemberInfo) ⇒ <code>Promise</code>
* [.getListMemberInfo(members)](#module_services.members..MembersService+getListMemberInfo) ⇒ <code>Promise</code>
* [.getExternalAccounts(handle)](#module_services.members..MembersService+getExternalAccounts) ⇒ <code>Promise</code>
* [.getExternalLinks(handle)](#module_services.members..MembersService+getExternalLinks) ⇒ <code>Promise</code>
* [.getSkills(handle)](#module_services.members..MembersService+getSkills) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -53,6 +54,7 @@ Service class.
* [new MembersService(tokenV3)](#new_module_services.members..MembersService_new)
* [.getMemberFinances(handle)](#module_services.members..MembersService+getMemberFinances) ⇒ <code>Promise</code>
* [.getMemberInfo(handle)](#module_services.members..MembersService+getMemberInfo) ⇒ <code>Promise</code>
* [.getListMemberInfo(members)](#module_services.members..MembersService+getListMemberInfo) ⇒ <code>Promise</code>
* [.getExternalAccounts(handle)](#module_services.members..MembersService+getExternalAccounts) ⇒ <code>Promise</code>
* [.getExternalLinks(handle)](#module_services.members..MembersService+getExternalLinks) ⇒ <code>Promise</code>
* [.getSkills(handle)](#module_services.members..MembersService+getSkills) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -104,6 +106,18 @@ This method does not require any authorization.
| --- | --- | --- |
| handle | <code>String</code> | Member handle. |

#### membersService.getListMemberInfo(members) ⇒ <code>Promise</code>
Gets public information on a list member.

This method does not require any authorization.

**Kind**: instance method of [<code>MembersService</code>](#module_services.members..MembersService)
**Returns**: <code>Promise</code> - Resolves to the array.

| Param | Type | Description |
| --- | --- | --- |
| members | <code>Array</code> | Array of member info. |

<a name="module_services.members..MembersService+getExternalAccounts"></a>

#### membersService.getExternalAccounts(handle) ⇒ <code>Promise</code>
Expand All @@ -114,7 +128,7 @@ Gets member external account info.

| Param | Type |
| --- | --- |
| handle | <code>String</code> |
| handle | <code>String</code> |

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

Expand All @@ -126,7 +140,7 @@ Gets member external links.

| Param | Type |
| --- | --- |
| handle | <code>String</code> |
| handle | <code>String</code> |

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

Expand All @@ -138,7 +152,7 @@ Gets member skills.

| Param | Type |
| --- | --- |
| handle | <code>String</code> |
| handle | <code>String</code> |

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

Expand All @@ -150,7 +164,7 @@ Gets member statistics.

| Param | Type |
| --- | --- |
| handle | <code>String</code> |
| handle | <code>String</code> |

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

Expand All @@ -162,7 +176,7 @@ Gets member statistics history

| Param | Type |
| --- | --- |
| handle | <code>String</code> |
| handle | <code>String</code> |

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

Expand All @@ -174,9 +188,9 @@ Gets member statistics distribution

| Param | Type |
| --- | --- |
| handle | <code>String</code> |
| track | <code>String</code> |
| subTrack | <code>String</code> |
| handle | <code>String</code> |
| track | <code>String</code> |
| subTrack | <code>String</code> |

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

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/actions/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,30 @@ function getCountriesDone() {
return getService().getCountries();
}

/**
* @static
* @desc Creates an action that signals beginning of getting all countries api version 5.
* @return {Action}
*/
function getAllCountriesInit() {}

/**
* @static
* @desc Creates an action that gets all countries api version 5.
* @param {String} tokenV3 Optional. Auth token for Topcoder API v3.
* @return {Action}
*/
function getAllCountriesDone(tokenV3) {
return getService(tokenV3).getAllCountries();
}

export default createActions({
LOOKUP: {
GET_SKILL_TAGS_INIT: getSkillTagsInit,
GET_SKILL_TAGS_DONE: getSkillTagsDone,
GET_COUNTRIES_INIT: getCountriesInit,
GET_COUNTRIES_DONE: getCountriesDone,
GET_ALL_COUNTRIES_INIT: getAllCountriesInit,
GET_ALL_COUNTRIES_DONE: getAllCountriesDone,
},
});
22 changes: 22 additions & 0 deletions src/reducers/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ function onGetCountriesDone(state, { payload, error }) {
});
}

/**
* Handles LOOKUP/GET_ALL_COUNTRIES_DONE action.
* @param {Object} state
* @param {Object} action Payload will be JSON from api call
* @return {Object} New state
*/
function onGetAllCountriesDone(state, { payload, error }) {
if (error) {
logger.error('Failed to get all countries', payload);
return { ...state, loadingAllCountriesError: true };
}

return ({
...state,
loadingAllCountriesError: false,
allCountries: payload,
});
}

/**
* Creates a new Lookup reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand All @@ -60,9 +79,12 @@ function create(initialState = {}) {
[a.getSkillTagsDone]: onGetSkillTagsDone,
[a.getCountriesInit]: state => state,
[a.getCountriesDone]: onGetCountriesDone,
[a.getAllCountriesInit]: state => state,
[a.getAllCountriesDone]: onGetAllCountriesDone,
}, _.defaults(initialState, {
skillTags: [],
countries: [],
allCountries: [],
}));
}

Expand Down
13 changes: 13 additions & 0 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import logger from '../utils/logger';
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
import { getApi } from './api';
import { getService as getMembersService } from './members';

export const ORDER_BY = {
SUBMISSION_END_DATE: 'submissionEndDate',
Expand Down Expand Up @@ -83,6 +84,15 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
registrants: challenge.registrants || [],
};


_.forEach(finalChallenge.registrants, (registrant) => {
if (registrant.memberInfo) {
const { homeCountryCode } = registrant.memberInfo;
// eslint-disable-next-line no-param-reassign
registrant.countryCode = homeCountryCode || registrant.memberInfo.competitionCountryCode;
}
});

// Winners have different field names, needs to be normalized to match `filtered` and `challenge`
finalChallenge.winners = _.map(
challenge.winners,
Expand Down Expand Up @@ -262,6 +272,7 @@ class ChallengesService {
getChallenges,
tokenV2,
tokenV3,
memberService: getMembersService(),
};
}

Expand Down Expand Up @@ -373,6 +384,8 @@ class ChallengesService {
const challengeUser = username && await this.getUserChallenges(username, { id: challengeId })
.then(res => res.challenges[0]).catch(() => null);

await this.private.memberService.getListMemberInfo(challenge.registrants || [], false);

const finalChallenge = normalizeChallengeDetails(
challenge,
challengeFiltered,
Expand Down
11 changes: 11 additions & 0 deletions src/services/lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class LookupService {
constructor(tokenV3) {
this.private = {
api: getApi('V3', tokenV3),
apiV5: getApi('V5', tokenV3),
tokenV3,
};
}
Expand All @@ -37,6 +38,16 @@ class LookupService {
const res = await this.private.api.get('/members/lookup/countries');
return getApiResponsePayload(res);
}

/**
* Gets all countries.
* @return {Promise} Resolves to the countries.
*/
async getAllCountries() {
const res = await this.private.apiV5.get('/lookups/countries');
const jsonResult = await res.json();
return jsonResult;
}
}

let lastInstance = null;
Expand Down
19 changes: 19 additions & 0 deletions src/services/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ class MembersService {
return getApiResponsePayload(res);
}

/**
* Gets public information on a list member.
*
* This method does not require any authorization.
*
* @param {Array} members List member info.
* @param {Boolean} shouldThrowError should throw error if request fail
* @return {Promise} Resolves to the data object.
*/
async getListMemberInfo(members, shouldThrowError = true) {
const getHandle = async (member) => {
const result = await this.private.api.get(`/members/${member.handle}`);
// eslint-disable-next-line no-param-reassign
member.memberInfo = await getApiResponsePayload(result, shouldThrowError);
};
const apis = members.map(member => getHandle(member));
await Promise.all(apis);
}

/**
* Gets member external account info.
* @param {String} handle
Expand Down
Loading