Skip to content
Open
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
21 changes: 18 additions & 3 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ async function checkErrorV5(res) {
};
}

/**
* check if is marathon match challenge
* @param {Object} challenge challenge object
* @return {Boolean}
* @private
*/
function checkMM(challenge) {
const tags = _.get(challenge, 'tags') || [];
return tags.includes('Marathon Match');
}

/**
* Challenge service.
*/
Expand Down Expand Up @@ -390,13 +401,17 @@ class ChallengesService {
.then(res => res.challenges);
}

const isMM = checkMM(challenge);

if (challenge) {
registrants = await this.getChallengeRegistrants(challenge.id);

// This TEMP fix to colorStyle, this will be fixed with issue #4530
registrants = _.map(registrants, r => ({
...r, colorStyle: 'color: #151516',
}));
registrants = await Promise.all(_.map(registrants, async r => ({
...r,
colorStyle: 'color: #151516',
rating: isMM ? await this.private.memberService.getMMRating(r.memberHandle) : r.rating,
})));

/* Prepare data to logged user */
if (memberId) {
Expand Down
19 changes: 19 additions & 0 deletions src/services/members.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ class MembersService {
);
}

/**
* Gets member Marathon Match rating.
* @param {String} handle
* @returns {Promise} resolves to the rating
*/
async getMMRating(handle) {
const res = await this.private.apiV5.get(`/members/${handle}/stats`);
const stats = await res.json();

if (stats.length === 1) {
if (stats[0].DATA_SCIENCE != null && stats[0].DATA_SCIENCE.MARATHON_MATCH != null) {
return stats[0].DATA_SCIENCE.MARATHON_MATCH.rank.rating;
}
return 0;
}

return 0;
}

/**
* Gets member statistics history
* @param {String} handle
Expand Down