Skip to content

Update to use v5 challenge API instead of v2 #372

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 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 4 additions & 7 deletions docs/actions.challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Actions related to Topcoder challenges APIs.
* [.unregisterInit()](#module_actions.challenge.unregisterInit) ⇒ <code>Action</code>
* [.unregisterDone(auth, challengeId)](#module_actions.challenge.unregisterDone) ⇒ <code>Action</code>
* [.loadResultsInit(challengeId)](#module_actions.challenge.loadResultsInit) ⇒ <code>Action</code>
* [.loadResultsDone(auth, challengeId, type)](#module_actions.challenge.loadResultsDone) ⇒ <code>Action</code>
* [.loadResultsDone(challengeId, tokenV3)](#module_actions.challenge.loadResultsDone) ⇒ <code>Action</code>
* [.fetchCheckpointsInit()](#module_actions.challenge.fetchCheckpointsInit) ⇒ <code>Action</code>
* [.fetchCheckpointsDone(tokenV2, challengeId)](#module_actions.challenge.fetchCheckpointsDone)
* [.toggleCheckpointFeedback(id, open)](#module_actions.challenge.toggleCheckpointFeedback) ⇒ <code>Action</code>
Expand Down Expand Up @@ -144,18 +144,15 @@ Creates an action that signals beginning of challenge results loading.

<a name="module_actions.challenge.loadResultsDone"></a>

### actions.challenge.loadResultsDone(auth, challengeId, type) ⇒ <code>Action</code>
### actions.challenge.loadResultsDone(challengeId, tokenV3) ⇒ <code>Action</code>
Creates an action that loads challenge results.

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

| Param | Type | Description |
| --- | --- | --- |
| auth | <code>Object</code> | Object that holds Topcoder auth tokens. |
| [auth.tokenV2] | <code>String</code> | v2 token. |
| [auth.tokenV3] | <code>String</code> | v3 token. |
| challengeId | <code>Number</code> \| <code>String</code> | Challenge ID. Should match the one passed in the previous [loadResultsInit](#module_actions.challenge.loadResultsInit) call. |
| type | <code>String</code> | Challenge type. |
| tokenV3 | <code>String</code> | Topcoder v3 auth token. |

<a name="module_actions.challenge.fetchCheckpointsInit"></a>

Expand Down
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.2.13",
"version": "1.2.14",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
22 changes: 8 additions & 14 deletions src/actions/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,16 @@ function loadResultsInit(challengeId) {
/**
* @static
* @desc Creates an action that loads challenge results.
* @param {Object} auth Object that holds Topcoder auth tokens.
* @param {String} [auth.tokenV2] v2 token.
* @param {String} [auth.tokenV3] v3 token.
* @param {Number|String} challengeId Challenge ID. Should match the one passed
* in the previous {@link module:actions.challenge.loadResultsInit} call.
* @param {String} type Challenge type.
* @param {String} challengeId The challenge id
* @param {String} tokenV3 Topcoder auth token v3.
* @return {Action}
*/
function loadResultsDone(auth, challengeId, type) {
return getApi('V2')
.fetch(`/${type}/challenges/result/${challengeId}`)
.then(response => response.json())
.then(response => ({
challengeId: _.toString(challengeId),
results: response.results,
}));
function loadResultsDone(challengeId, tokenV3) {
const service = getChallengesService(tokenV3);
return service.getChallengeDetails(challengeId).then(response => ({
challengeId,
results: response.winners,
}));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export function factory(options = {}) {
}
const resultsPromise = challengeDetails.status === 'Completed' ? (
redux.resolveAction(
actions.challenge.loadResultsDone(tokens, challengeId, track.toLowerCase()),
actions.challenge.loadResultsDone(challengeId, tokens.tokenV3),
)
) : null;
return Promise.all([res, checkpointsPromise, resultsPromise]);
Expand Down