Skip to content

Commit 68b22f7

Browse files
few fixes and notes on what needs to be fixed
1 parent 7e89f22 commit 68b22f7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/services/challenges.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export const ORDER_BY = {
3535
* @return {Object} Normalized challenge object.
3636
*/
3737
export function normalizeChallengeDetails(challenge, filtered, user, username) {
38+
// FIXME: This has not been updated to use V5
39+
// We should not be modifying the challenge data to get it in shape.
40+
// Instead, we should be modifying the frontend to be able to
41+
// consume the data as it comes from the API.
42+
// So, Ideally, this method should be removed
43+
// ------------------------------------
3844
// Normalize exising data to make it consistent with the rest of the code
3945
const finalChallenge = {
4046
...challenge,
@@ -173,6 +179,11 @@ export function normalizeChallengeDetails(challenge, filtered, user, username) {
173179
* @param {String} username Optional.
174180
*/
175181
export function normalizeChallenge(challenge, username) {
182+
// FIXME: This has not been updated to use V5
183+
// We should not be modifying the challenge data to get it in shape.
184+
// Instead, we should be modifying the frontend to be able to
185+
// consume the data as it comes from the API.
186+
// So, Ideally, this method should be removed
176187
const registrationOpen = (challenge.allPhases || challenge.phases || []).filter(d => (d.name === 'Registration' || !d.name))[0].isOpen ? 'Yes' : 'No';
177188
const groups = {};
178189
if (challenge.groupIds) {
@@ -304,6 +315,9 @@ class ChallengesService {
304315
...params,
305316
};
306317
const url = `${endpoint}?${qs.stringify(query)}`;
318+
// FIXME: This has not been updated to use the V5 API
319+
// Ref: http://api.topcoder-dev.com/v5/challenges/docs/#/Challenges/get_challenges
320+
// Use the `memberId` query parameter to filter challenges for a specific member
307321
const res = await this.private.api.get(url).then(checkError);
308322
return {
309323
challenges: res.content || [],
@@ -353,7 +367,7 @@ class ChallengesService {
353367
const params = {
354368
status: 'Completed',
355369
};
356-
let res = await this.private.apiV5.patch(`/challenges/${challengeId}/close`, params);
370+
let res = await this.private.apiV5.patch(`/challenges/${challengeId}`, params);
357371
if (!res.ok) throw new Error(res.statusText);
358372
res = (await res.json()).result;
359373
if (res.status !== 200) throw new Error(res.content);
@@ -387,6 +401,7 @@ class ChallengesService {
387401
tags,
388402
) {
389403
const payload = {
404+
// FIXME: This has not been updated to use the v5 API
390405
param: {
391406
assignees: [assignee],
392407
billingAccountId: accountId,
@@ -457,6 +472,10 @@ class ChallengesService {
457472
* @return {Promise} Resolves to the challenge registrants array.
458473
*/
459474
async getChallengeRegistrants(challengeId) {
475+
// FIXME: The implementation here is wrong.
476+
// The correct implementation would be to call the Resources API to fetch the
477+
// resources for the given challenge and filter based on the registrant resource role ID
478+
// Ref: http://api.topcoder-dev.com/v5/resources/docs/#/Resources/get_resources
460479
const challenge = await this.private.apiV5.get(`/challenges/${challengeId}`)
461480
.then(checkError).then(res => res);
462481
return challenge.registrants || [];
@@ -532,6 +551,7 @@ class ChallengesService {
532551
* @return {Promise} Resolves to the api response.
533552
*/
534553
getUserChallenges(username, filters, params) {
554+
// FIXME: This has not been updated to use the V5 API
535555
const userFilters = _.cloneDeep(filters);
536556
ChallengesService.updateFiltersParamsForGettingMemberChallenges(userFilters, params);
537557
const endpoint = `/members/${username.toLowerCase()}/challenges/`;
@@ -550,6 +570,7 @@ class ChallengesService {
550570
* @return {Promise} Resolves to the api response.
551571
*/
552572
getUserMarathonMatches(username, filters, params) {
573+
// FIXME: This has not been updated to use the V5 API
553574
ChallengesService.updateFiltersParamsForGettingMemberChallenges(filters, params);
554575
const endpoint = `/members/${username.toLowerCase()}/mms/`;
555576
return this.private.getMemberChallenges(endpoint, filters, params);
@@ -562,6 +583,7 @@ class ChallengesService {
562583
* @return {Promise}
563584
*/
564585
async getUserSrms(handle, params) {
586+
// FIXME: This has not been updated to use the V5 API
565587
const url = `/members/${handle}/srms/?${qs.stringify(params)}`;
566588
const res = await this.private.api.get(url);
567589
return getApiResponsePayload(res);
@@ -594,7 +616,7 @@ class ChallengesService {
594616
const params = {
595617
challengeId, memberHandle, roleId,
596618
};
597-
const res = await this.private.apiV5.post('/resources', params);
619+
const res = await this.private.apiV5.delete('/resources', params);
598620
if (!res.ok) throw new Error(res.statusText);
599621
return res.json();
600622
}

0 commit comments

Comments
 (0)