Skip to content

Commit 4c90de5

Browse files
author
Rakib Ansary
committed
fix: #4947 marathon match rating
* use members mm rating instead of maxRating in mm challenges
1 parent 0fece44 commit 4c90de5

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/services/challenges.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ async function checkErrorV5(res) {
150150
};
151151
}
152152

153+
/**
154+
* check if is marathon match challenge
155+
* @param {Object} challenge challenge object
156+
* @return {Boolean}
157+
* @private
158+
*/
159+
function checkMM(challenge) {
160+
const tags = _.get(challenge, 'tags') || [];
161+
return tags.includes('Marathon Match');
162+
}
163+
153164
/**
154165
* Challenge service.
155166
*/
@@ -390,13 +401,17 @@ class ChallengesService {
390401
.then(res => res.challenges);
391402
}
392403

404+
const isMM = checkMM(challenge);
405+
393406
if (challenge) {
394407
registrants = await this.getChallengeRegistrants(challenge.id);
395408

396409
// This TEMP fix to colorStyle, this will be fixed with issue #4530
397-
registrants = _.map(registrants, r => ({
398-
...r, colorStyle: 'color: #151516',
399-
}));
410+
registrants = await Promise.all(_.map(registrants, async r => ({
411+
...r,
412+
colorStyle: 'color: #151516',
413+
rating: isMM ? await this.private.memberService.getMMRating(r.memberHandle) : r.rating,
414+
})));
400415

401416
/* Prepare data to logged user */
402417
if (memberId) {

src/services/members.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,25 @@ class MembersService {
109109
);
110110
}
111111

112+
/**
113+
* Gets member Marathon Match rating.
114+
* @param {String} handle
115+
* @returns {Promise} resolves to the rating
116+
*/
117+
async getMMRating(handle) {
118+
const res = await this.private.apiV5.get(`/members/${handle}/stats`);
119+
const stats = await res.json();
120+
121+
if (stats.length === 1) {
122+
if (stats[0].DATA_SCIENCE != null && stats[0].DATA_SCIENCE.MARATHON_MATCH != null) {
123+
return stats[0].DATA_SCIENCE.MARATHON_MATCH.rank.rating;
124+
}
125+
return 0;
126+
}
127+
128+
return 0;
129+
}
130+
112131
/**
113132
* Gets member statistics history
114133
* @param {String} handle

0 commit comments

Comments
 (0)