@@ -10,8 +10,8 @@ import qs from 'qs';
1010import { decodeToken } from 'tc-accounts' ;
1111import logger from '../utils/logger' ;
1212import { setErrorIcon , ERROR_ICON_TYPES } from '../utils/errors' ;
13- import { COMPETITION_TRACKS , getApiResponsePayloadV3 } from '../utils/tc' ;
14- import { getApiV2 , getApiV3 , getApiV4 } from './api' ;
13+ import { COMPETITION_TRACKS , getApiResponsePayload } from '../utils/tc' ;
14+ import { getApiV2 , getApiV4 } from './api' ;
1515
1616export const ORDER_BY = {
1717 SUBMISSION_END_DATE : 'submissionEndDate' ,
@@ -86,7 +86,7 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
8686 registrants : v4 . registrants || [ ] ,
8787 } ;
8888
89- // v4 Winners have different field names, needs to be normalized to match v4 filtered and v3
89+ // v4 Winners have different field names, needs to be normalized to match v4 filtered and v4
9090 challenge . winners = _ . map (
9191 v4 . winners ,
9292 ( winner , index ) => ( {
@@ -117,22 +117,22 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
117117 componentId : v4Filtered . componentId ,
118118 contestId : v4Filtered . contestId ,
119119
120- submissionEndDate : v4Filtered . submissionEndDate , // Dates are not correct in v3
121- submissionEndTimestamp : v4Filtered . submissionEndDate , // Dates are not correct in v3
120+ submissionEndDate : v4Filtered . submissionEndDate , // Dates are not correct in v4
121+ submissionEndTimestamp : v4Filtered . submissionEndDate , // Dates are not correct in v4
122122
123- /* Taking phases from v3_filtered , because dates are not correct in v3 */
123+ /* Taking phases from v4_filtered , because dates are not correct in v4 */
124124 allPhases : v4Filtered . allPhases || [ ] ,
125125
126- /* Taking phases from v3_filtered , because dates are not correct in v3 */
126+ /* Taking phases from v4_filtered , because dates are not correct in v4 */
127127 currentPhases : v4Filtered . currentPhases || [ ] ,
128128
129- /* v3 returns incorrect value for numberOfSubmissions for some reason */
129+ /* v4 returns incorrect value for numberOfSubmissions for some reason */
130130 numSubmissions : v4Filtered . numSubmissions ,
131131 groups,
132132 } ) ;
133133 }
134134
135- // Fill missing data from v3_user
135+ // Fill missing data from v4_user
136136 if ( v4User ) {
137137 _ . defaults ( challenge , {
138138 userDetails : v4User . userDetails ,
@@ -168,7 +168,7 @@ export function normalizeChallengeDetails(v4, v4Filtered, v4User, username) {
168168 * Normalizes a regular challenge object received from the backend.
169169 * NOTE: This function is copied from the existing code in the challenge listing
170170 * component. It is possible, that this normalization is not necessary after we
171- * have moved to Topcoder API v3 , but it is kept for now to minimize a risk of
171+ * have moved to Topcoder API v4 , but it is kept for now to minimize a risk of
172172 * breaking anything.
173173 * @todo Should be used only internally!
174174 * @param {Object } challenge Challenge object received from the backend.
@@ -251,7 +251,7 @@ class ChallengesService {
251251 ...params ,
252252 } ;
253253 const url = `${ endpoint } ?${ qs . stringify ( query ) } ` ;
254- const res = await this . private . apiV4 . get ( url ) . then ( checkError ) ;
254+ const res = await this . private . api . get ( url ) . then ( checkError ) ;
255255 return {
256256 challenges : res . content || [ ] ,
257257 totalCount : res . metadata . totalCount ,
@@ -261,7 +261,6 @@ class ChallengesService {
261261 this . private = {
262262 api : getApiV4 ( tokenV3 ) ,
263263 apiV2 : getApiV2 ( tokenV2 ) ,
264- apiV4 : getApiV4 ( tokenV3 ) ,
265264 getChallenges,
266265 tokenV2,
267266 tokenV3,
@@ -359,14 +358,14 @@ class ChallengesService {
359358
360359 /**
361360 * Gets challenge details from Topcoder API v4.
362- * NOTE: This function also uses API v2 and other v3 endpoints for now, due
361+ * NOTE: This function also uses API v2 and other v4 endpoints for now, due
363362 * to some information is missing or
364- * incorrect in the main v3 endpoint. This may change in the future.
363+ * incorrect in the main v4 endpoint. This may change in the future.
365364 * @param {Number|String } challengeId
366365 * @return {Promise } Resolves to the challenge object.
367366 */
368367 async getChallengeDetails ( challengeId ) {
369- const challengeV4 = await this . private . apiV4 . get ( `/challenges/${ challengeId } ` )
368+ const challengeV4 = await this . private . api . get ( `/challenges/${ challengeId } ` )
370369 . then ( checkError ) . then ( res => res . content ) ;
371370
372371 const challengeV4Filtered = await this . private . getChallenges ( '/challenges/' , { id : challengeId } )
@@ -437,7 +436,7 @@ class ChallengesService {
437436 */
438437 async getSrms ( params ) {
439438 const res = await this . private . api . get ( `/srms/?${ qs . stringify ( params ) } ` ) ;
440- return getApiResponsePayloadV3 ( res ) ;
439+ return getApiResponsePayload ( res ) ;
441440 }
442441
443442 /**
@@ -466,7 +465,7 @@ class ChallengesService {
466465 async getUserSrms ( handle , params ) {
467466 const url = `/members/${ handle } /srms/?${ qs . stringify ( params ) } ` ;
468467 const res = await this . private . api . get ( url ) ;
469- return getApiResponsePayloadV3 ( res ) ;
468+ return getApiResponsePayload ( res ) ;
470469 }
471470
472471 /**
@@ -476,7 +475,7 @@ class ChallengesService {
476475 */
477476 async register ( challengeId ) {
478477 const endpoint = `/challenges/${ challengeId } /register` ;
479- const res = await this . private . apiV4 . postJson ( endpoint ) ;
478+ const res = await this . private . api . postJson ( endpoint ) ;
480479 if ( ! res . ok ) throw new Error ( res . statusText ) ;
481480 return res . json ( ) ;
482481 }
@@ -488,7 +487,7 @@ class ChallengesService {
488487 */
489488 async unregister ( challengeId ) {
490489 const endpoint = `/challenges/${ challengeId } /unregister` ;
491- const res = await this . private . apiV4 . post ( endpoint ) ;
490+ const res = await this . private . api . post ( endpoint ) ;
492491 if ( ! res . ok ) throw new Error ( res . statusText ) ;
493492 return res . json ( ) ;
494493 }
0 commit comments