From bfef016bcbb229d885d088f01feb2b6efc9b8390 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Wed, 24 Jun 2020 20:21:22 -0300 Subject: [PATCH 1/7] Update getSubmissionsDone() to use V5 API --- src/actions/challenge.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/actions/challenge.js b/src/actions/challenge.js index 4627c0a3..e15890e8 100644 --- a/src/actions/challenge.js +++ b/src/actions/challenge.js @@ -103,12 +103,12 @@ function getSubmissionsInit(challengeId) { * @desc Creates an action that loads user's submissions to the specified * challenge. * @param {String} challengeId Challenge ID. - * @param {String} tokenV2 Topcoder auth token v2. + * @param {String} tokenV23 Topcoder auth token v3. * @return {Action} */ -function getSubmissionsDone(challengeId, tokenV2) { - return getApi('V2', tokenV2) - .fetch(`/challenges/submissions/${challengeId}/mySubmissions`) +function getSubmissionsDone(challengeId, tokenV3) { + return getApi('V5', tokenV3) + .fetch(`/submissions?challengeId=${challengeId}`) .then(response => response.json()) .then(response => ({ challengeId: _.toString(challengeId), From d593f70eb79a4a3b651ea5e3d9a9f62a8985c855 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Thu, 25 Jun 2020 17:42:55 -0300 Subject: [PATCH 2/7] Updated var type from Number to String to challengeId --- src/actions/challenge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/challenge.js b/src/actions/challenge.js index e15890e8..9c216226 100644 --- a/src/actions/challenge.js +++ b/src/actions/challenge.js @@ -289,13 +289,13 @@ function fetchCheckpointsDone(tokenV2, challengeId) { response.checkpointResults[index].expanded = false; }); return { - challengeId: Number(challengeId), + challengeId: String(challengeId), checkpoints: response, }; }) .catch(error => ({ error, - challengeId: Number(challengeId), + challengeId: String(challengeId), })); } From 1c8f9f295075f9f5e30f0b77d9b880c65cdacb57 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Thu, 25 Jun 2020 17:44:42 -0300 Subject: [PATCH 3/7] Update getSubmissions to use UUID instead legacyId --- src/services/challenges.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/services/challenges.js b/src/services/challenges.js index 25811f62..b7967a09 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -350,14 +350,15 @@ class ChallengesService { if (memberId) { isRegistered = _.some(registrants, r => r.memberId === memberId); - /** - * TODO: Currenlty using legacyId until submissions_api fix issue with UUID - */ const subParams = { - challengeId: challenge.legacyId, + challengeId, perPage: 100, }; - submissions = await this.private.submissionsService.getSubmissions(subParams); + try { + submissions = await this.private.submissionsService.getSubmissions(subParams); + } catch (err) { + submissions = []; + } if (submissions) { // Remove AV Scan, SonarQube Review and Virus Scan review types From bed729f4e1c8b9d4bd4683cca2ef0a68d262efec Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Thu, 25 Jun 2020 17:45:17 -0300 Subject: [PATCH 4/7] Added checkErrorV5 to submissions services --- src/services/submissions.js | 40 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/services/submissions.js b/src/services/submissions.js index 36e78fb6..12f27021 100644 --- a/src/services/submissions.js +++ b/src/services/submissions.js @@ -5,8 +5,32 @@ */ import _ from 'lodash'; import qs from 'qs'; +import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors'; import { getApi } from './api'; +/** + * Helper method that checks for HTTP error response v5 and throws Error in this case. + * @param {Object} res HTTP response object + * @return {Object} API JSON response object + * @private + */ +async function checkErrorV5(res) { + if (!res.ok) { + if (res.status >= 500) { + setErrorIcon(ERROR_ICON_TYPES.API, '/challenges', res.statusText); + } + throw new Error(res.statusText); + } + const jsonRes = (await res.json()); + if (jsonRes.message) { + throw new Error(res.message); + } + return { + result: jsonRes, + headers: res.headers, + }; +} + /** * Submission service. */ @@ -36,8 +60,8 @@ class SubmissionsService { const url = `/submissions?${qs.stringify(query, { encode: false })}`; return this.private.apiV5.get(url) - .then(res => (res.ok ? res.json() : new Error(res.statusText))) - .then(res => res); + .then(checkErrorV5) + .then(res => res.result); } /** @@ -47,14 +71,14 @@ class SubmissionsService { async getScanReviewIds() { const reviews = await Promise.all([ this.private.apiV5.get('/reviewTypes?name=AV Scan') - .then(res => (res.ok ? res.json() : new Error(res.statusText))) - .then(res => res), + .then(checkErrorV5) + .then(res => res.result), this.private.apiV5.get('/reviewTypes?name=SonarQube Review') - .then(res => (res.ok ? res.json() : new Error(res.statusText))) - .then(res => res), + .then(checkErrorV5) + .then(res => res.result), this.private.apiV5.get('/reviewTypes?name=Virus Scan') - .then(res => (res.ok ? res.json() : new Error(res.statusText))) - .then(res => res), + .then(checkErrorV5) + .then(res => res.result), ]).then(([av, sonar, virus]) => (_.concat(av, sonar, virus))); return reviews.map(r => r.id); From 5407a2663414dcce96a8304f4f9f4bb460cc1276 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 29 Jun 2020 22:43:53 -0300 Subject: [PATCH 5/7] Updated action getSubmissionsDone to use submissionsService --- src/actions/challenge.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/actions/challenge.js b/src/actions/challenge.js index 9c216226..c8fa4ace 100644 --- a/src/actions/challenge.js +++ b/src/actions/challenge.js @@ -7,6 +7,7 @@ import _ from 'lodash'; import { config } from 'topcoder-react-utils'; import { createActions } from 'redux-actions'; +import { decodeToken } from 'tc-accounts'; import { getService as getChallengesService } from '../services/challenges'; import { getService as getSubmissionService } from '../services/submissions'; import { getService as getMemberService } from '../services/members'; @@ -103,16 +104,20 @@ function getSubmissionsInit(challengeId) { * @desc Creates an action that loads user's submissions to the specified * challenge. * @param {String} challengeId Challenge ID. - * @param {String} tokenV23 Topcoder auth token v3. + * @param {String} tokenV3 Topcoder auth token v3. * @return {Action} */ function getSubmissionsDone(challengeId, tokenV3) { - return getApi('V5', tokenV3) - .fetch(`/submissions?challengeId=${challengeId}`) - .then(response => response.json()) - .then(response => ({ + const user = decodeToken(tokenV3); + const submissionsService = getSubmissionService(tokenV3); + const filters = { + challengeId, + memberId: user.userId, + }; + return submissionsService.getSubmissions(filters) + .then(submissions => ({ challengeId: _.toString(challengeId), - submissions: response.submissions, + submissions, })) .catch((error) => { const err = { challengeId: _.toString(challengeId), error }; From 4432f22922739fd79761f7d4ca3a2db6d7bb23c6 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 29 Jun 2020 22:44:15 -0300 Subject: [PATCH 6/7] Updated deleteSubmissionDone to use V5 API --- src/actions/smp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/smp.js b/src/actions/smp.js index 9c46f513..bded6d70 100644 --- a/src/actions/smp.js +++ b/src/actions/smp.js @@ -22,7 +22,7 @@ function deleteSubmissionInit() {} * @return {Action} */ function deleteSubmissionDone(tokenV3, submissionId) { - return getApi('V3', tokenV3).delete(`/submissions/${submissionId}`) + return getApi('V5', tokenV3).delete(`/submissions/${submissionId}`) .then(() => submissionId); } From 910cebfa23c524cadf6e561e18f20c201c6dabc8 Mon Sep 17 00:00:00 2001 From: "Luiz R. Rodrigues" Date: Mon, 29 Jun 2020 22:44:50 -0300 Subject: [PATCH 7/7] Remove try/catch from get submissions in challenge details --- src/services/challenges.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/services/challenges.js b/src/services/challenges.js index b7967a09..079a5ef7 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -354,11 +354,8 @@ class ChallengesService { challengeId, perPage: 100, }; - try { - submissions = await this.private.submissionsService.getSubmissions(subParams); - } catch (err) { - submissions = []; - } + + submissions = await this.private.submissionsService.getSubmissions(subParams); if (submissions) { // Remove AV Scan, SonarQube Review and Virus Scan review types pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy