diff --git a/src/services/challenges.js b/src/services/challenges.js index 7c02078..5031bbb 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -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. */ @@ -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) { diff --git a/src/services/members.js b/src/services/members.js index ce07921..e525aa3 100644 --- a/src/services/members.js +++ b/src/services/members.js @@ -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