Skip to content

Commit d25ed67

Browse files
Updated getChallengeDetails to get registrants
Updated getChallengeRegistrants to use proxyAPi
1 parent c19bc09 commit d25ed67

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/services/challenges.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { decodeToken } from 'tc-accounts';
1111
import logger from '../utils/logger';
1212
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
1313
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
14-
import { getApi } from './api';
14+
import { getApi, proxyApi } from './api';
1515
import { getService as getMembersService } from './members';
1616

1717
export const ORDER_BY = {
@@ -200,6 +200,7 @@ class ChallengesService {
200200
apiV3: getApi('V3', tokenV3),
201201
getChallenges,
202202
getMemberChallenges,
203+
proxyApi,
203204
tokenV2,
204205
tokenV3,
205206
memberService: getMembersService(),
@@ -325,27 +326,32 @@ class ChallengesService {
325326
* @return {Promise} Resolves to the challenge object.
326327
*/
327328
async getChallengeDetails(challengeId) {
329+
let challenge = {};
328330
let isLegacyChallenge = false;
329-
const filters = {};
330331
// condition based on ROUTE used for Review Opportunities, change if needed
331-
if (challengeId.length >= 5 && challengeId.length <= 8) {
332+
if (/^[\d]{5,8}$/.test(challengeId)) {
332333
isLegacyChallenge = true;
333-
filters.legacyId = challengeId;
334+
challenge = await this.private.getChallenges('/challenges/', { legacyId: challengeId })
335+
.then(res => res.challenges[0]);
334336
} else {
335-
filters.id = challengeId;
337+
challenge = await this.private.getChallenges(`/challenges/${challengeId}`)
338+
.then(res => res.challenges);
336339
}
337-
const challengeFiltered = await this.private.getChallenges('/challenges/', filters)
338-
.then(res => res.challenges[0]);
339-
340-
if (challengeFiltered) {
341-
challengeFiltered.isLegacyChallenge = isLegacyChallenge;
342-
challengeFiltered.events = _.map(challengeFiltered.events, e => ({
343-
eventName: e.key,
344-
eventId: e.id,
345-
description: e.name,
346-
}));
347-
}
348-
return challengeFiltered;
340+
341+
const registrants = await this.getChallengeRegistrants(challenge.id);
342+
challenge.registrants = registrants;
343+
344+
challenge.isLegacyChallenge = isLegacyChallenge;
345+
346+
challenge.events = _.map(challenge.events, e => ({
347+
eventName: e.key,
348+
eventId: e.id,
349+
description: e.name,
350+
}));
351+
352+
challenge.fetchedWithAuth = Boolean(this.private.apiV5.private.token);
353+
354+
return challenge;
349355
}
350356

351357
/**
@@ -354,8 +360,7 @@ class ChallengesService {
354360
* @return {Promise} Resolves to the challenge registrants array.
355361
*/
356362
async getChallengeRegistrants(challengeId) {
357-
const registrants = await this.private.apiV5.get(`/resources/challengeId=${challengeId}`)
358-
.then(checkError).then(res => res);
363+
const registrants = await this.private.proxyApi(`/challenges/${challengeId}/registrants`);
359364
return registrants || [];
360365
}
361366

0 commit comments

Comments
 (0)