Skip to content

fix(ChallengeDetails): return userDetails.roles with challenge details #214

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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "1000.19.39",
"version": "1000.19.40",
"dependencies": {
"auth0-js": "^6.8.4",
"config": "^3.2.0",
Expand Down
10 changes: 7 additions & 3 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ class ChallengesService {
let submissions = [];
let isLegacyChallenge = false;
let isRegistered = false;
const userDetails = { roles: [] };

// condition based on ROUTE used for Review Opportunities, change if needed
if (/^[\d]{5,8}$/.test(challengeId)) {
Expand Down Expand Up @@ -372,6 +373,7 @@ class ChallengesService {
}
});
}
userDetails.roles = await this.getUserRolesInChallenge(challengeId);
}

challenge = {
Expand All @@ -380,6 +382,7 @@ class ChallengesService {
isRegistered,
registrants,
submissions,
userDetails,
events: _.map(challenge.events, e => ({
eventName: e.key,
eventId: e.id,
Expand Down Expand Up @@ -703,9 +706,10 @@ class ChallengesService {
*/
async getUserRolesInChallenge(challengeId) {
const user = decodeToken(this.private.tokenV3);
const url = `/resources?challengeId=${challengeId}?memberHandle=${user.handle}`;
const resources = await this.private.apiV5.get(url);
if (resources) return _.map(resources, 'roleId');
const url = `/resources?challengeId=${challengeId}&memberHandle=${user.handle}`;
const getResourcesResponse = await this.private.apiV5.get(url);
const resources = await getResourcesResponse.json();
if (resources) return _.map(_.filter(resources, r => r.memberHandle === user.handle), 'roleId');
throw new Error(`Failed to fetch user role from challenge #${challengeId}`);
}
}
Expand Down