Skip to content

Commit b9ad775

Browse files
Removed proxyApi
1 parent e26398e commit b9ad775

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/services/api.js

-18
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,3 @@ export async function getTcM2mToken() {
290290
const token = await m2m.getMachineToken(TC_M2M.CLIENT_ID, TC_M2M.CLIENT_SECRET);
291291
return token;
292292
}
293-
294-
/**
295-
* Call API via proxy
296-
*
297-
* @param {String} url to API endpoint
298-
*/
299-
export async function proxyApi(endpoint) {
300-
let domain = '';
301-
if (isomorphy.isServerSide()) {
302-
domain = `http://${config.ENV.HOST || 'localhost'}:${config.ENV.PORT || 3000}`;
303-
}
304-
const url = `${domain}/community-app-assets/api${endpoint}`;
305-
let res = await fetch(url);
306-
if (!res.ok) throw new Error(res.statusText);
307-
res = (await res.json());
308-
if (res.message) throw new Error(res.message);
309-
return res;
310-
}

src/services/challenges.js

+17-4
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, proxyApi } from './api';
14+
import { getApi } from './api';
1515
import { getService as getMembersService } from './members';
1616

1717
export const ORDER_BY = {
@@ -200,7 +200,6 @@ class ChallengesService {
200200
apiV3: getApi('V3', tokenV3),
201201
getChallenges,
202202
getMemberChallenges,
203-
proxyApi,
204203
tokenV2,
205204
tokenV3,
206205
memberService: getMembersService(),
@@ -360,7 +359,19 @@ class ChallengesService {
360359
* @return {Promise} Resolves to the challenge registrants array.
361360
*/
362361
async getChallengeRegistrants(challengeId) {
363-
const registrants = await this.private.proxyApi(`/challenges/${challengeId}/registrants`);
362+
const roleId = await this.getRoleId('Submitter');
363+
const params = {
364+
challengeId,
365+
roleId,
366+
};
367+
368+
const registrants = await this.private.apiV5.get(`/resources?${qs.stringify(params)}`)
369+
.then(checkErrorV5).then(res => res.result);
370+
371+
if (_.isEmpty(registrants)) {
372+
throw new Error('Resource Role not found!');
373+
}
374+
364375
return registrants || [];
365376
}
366377

@@ -526,8 +537,10 @@ class ChallengesService {
526537
async getRoleId(roleName) {
527538
const params = {
528539
name: roleName,
540+
isActive: true,
529541
};
530-
const roles = await this.private.proxyApi(`/challenges/roleId?${qs.stringify(params)}`);
542+
const roles = await this.private.apiV5.get(`/resource-roles?${qs.stringify(params)}`)
543+
.then(checkErrorV5).then(res => res.result);
531544

532545
if (_.isEmpty(roles)) {
533546
throw new Error('Resource Role not found!');

0 commit comments

Comments
 (0)