Skip to content

Issue4380 : Removed proxyApi and TEMP fix to registrants #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Removed proxyApi
  • Loading branch information
luizrrodrigues committed Jun 12, 2020
commit b9ad775d3203298100f69159f0436bd2b445f04f
18 changes: 0 additions & 18 deletions src/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,3 @@ export async function getTcM2mToken() {
const token = await m2m.getMachineToken(TC_M2M.CLIENT_ID, TC_M2M.CLIENT_SECRET);
return token;
}

/**
* Call API via proxy
*
* @param {String} url to API endpoint
*/
export async function proxyApi(endpoint) {
let domain = '';
if (isomorphy.isServerSide()) {
domain = `http://${config.ENV.HOST || 'localhost'}:${config.ENV.PORT || 3000}`;
}
const url = `${domain}/community-app-assets/api${endpoint}`;
let res = await fetch(url);
if (!res.ok) throw new Error(res.statusText);
res = (await res.json());
if (res.message) throw new Error(res.message);
return res;
}
21 changes: 17 additions & 4 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { decodeToken } from 'tc-accounts';
import logger from '../utils/logger';
import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
import { getApi, proxyApi } from './api';
import { getApi } from './api';
import { getService as getMembersService } from './members';

export const ORDER_BY = {
Expand Down Expand Up @@ -200,7 +200,6 @@ class ChallengesService {
apiV3: getApi('V3', tokenV3),
getChallenges,
getMemberChallenges,
proxyApi,
tokenV2,
tokenV3,
memberService: getMembersService(),
Expand Down Expand Up @@ -360,7 +359,19 @@ class ChallengesService {
* @return {Promise} Resolves to the challenge registrants array.
*/
async getChallengeRegistrants(challengeId) {
const registrants = await this.private.proxyApi(`/challenges/${challengeId}/registrants`);
const roleId = await this.getRoleId('Submitter');
const params = {
challengeId,
roleId,
};

const registrants = await this.private.apiV5.get(`/resources?${qs.stringify(params)}`)
.then(checkErrorV5).then(res => res.result);

if (_.isEmpty(registrants)) {
throw new Error('Resource Role not found!');
}

return registrants || [];
}

Expand Down Expand Up @@ -526,8 +537,10 @@ class ChallengesService {
async getRoleId(roleName) {
const params = {
name: roleName,
isActive: true,
};
const roles = await this.private.proxyApi(`/challenges/roleId?${qs.stringify(params)}`);
const roles = await this.private.apiV5.get(`/resource-roles?${qs.stringify(params)}`)
.then(checkErrorV5).then(res => res.result);

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