Skip to content

Commit 84f8918

Browse files
committed
Fixes to use v5 challenge API instead of v2
https://topcoder.atlassian.net/browse/PS-187
1 parent f77ea84 commit 84f8918

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

docs/actions.challenge.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Actions related to Topcoder challenges APIs.
1616
* [.unregisterInit()](#module_actions.challenge.unregisterInit) ⇒ <code>Action</code>
1717
* [.unregisterDone(auth, challengeId)](#module_actions.challenge.unregisterDone) ⇒ <code>Action</code>
1818
* [.loadResultsInit(challengeId)](#module_actions.challenge.loadResultsInit) ⇒ <code>Action</code>
19-
* [.loadResultsDone(auth, challengeId, type)](#module_actions.challenge.loadResultsDone) ⇒ <code>Action</code>
19+
* [.loadResultsDone(challengeId, tokenV3)](#module_actions.challenge.loadResultsDone) ⇒ <code>Action</code>
2020
* [.fetchCheckpointsInit()](#module_actions.challenge.fetchCheckpointsInit) ⇒ <code>Action</code>
2121
* [.fetchCheckpointsDone(tokenV2, challengeId)](#module_actions.challenge.fetchCheckpointsDone)
2222
* [.toggleCheckpointFeedback(id, open)](#module_actions.challenge.toggleCheckpointFeedback) ⇒ <code>Action</code>
@@ -144,18 +144,15 @@ Creates an action that signals beginning of challenge results loading.
144144

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

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

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

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

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

src/actions/challenge.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,16 @@ function loadResultsInit(challengeId) {
239239
/**
240240
* @static
241241
* @desc Creates an action that loads challenge results.
242-
* @param {Object} auth Object that holds Topcoder auth tokens.
243-
* @param {String} [auth.tokenV2] v2 token.
244-
* @param {String} [auth.tokenV3] v3 token.
245-
* @param {Number|String} challengeId Challenge ID. Should match the one passed
246-
* in the previous {@link module:actions.challenge.loadResultsInit} call.
247-
* @param {String} type Challenge type.
242+
* @param {String} challengeId The challenge id
243+
* @param {String} tokenV3 Topcoder auth token v3.
248244
* @return {Action}
249245
*/
250-
function loadResultsDone(auth, challengeId, type) {
251-
return getApi('V2')
252-
.fetch(`/${type}/challenges/result/${challengeId}`)
253-
.then(response => response.json())
254-
.then(response => ({
255-
challengeId: _.toString(challengeId),
256-
results: response.results,
257-
}));
246+
function loadResultsDone(challengeId, tokenV3) {
247+
const service = getChallengesService(tokenV3);
248+
return service.getChallengeDetails(challengeId).then(response => ({
249+
challengeId,
250+
results: response.winners,
251+
}));
258252
}
259253

260254
/**

src/reducers/challenge.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ export function factory(options = {}) {
520520
}
521521
const resultsPromise = challengeDetails.status === 'Completed' ? (
522522
redux.resolveAction(
523-
actions.challenge.loadResultsDone(tokens, challengeId, track.toLowerCase()),
523+
actions.challenge.loadResultsDone(challengeId, tokens.tokenV3),
524524
)
525525
) : null;
526526
return Promise.all([res, checkpointsPromise, resultsPromise]);

0 commit comments

Comments
 (0)