diff --git a/src/services/challenges.js b/src/services/challenges.js index 079a5ef7..5c453f66 100644 --- a/src/services/challenges.js +++ b/src/services/challenges.js @@ -19,6 +19,25 @@ export const ORDER_BY = { SUBMISSION_END_DATE: 'submissionEndDate', }; +export function fixColorStyle(registrant) { + /* eslint-disable no-param-reassign */ + // set default color + registrant.colorStyle = 'color: #555555'; // grey + if (registrant.rating) { + if (registrant.rating >= 2200) { + registrant.colorStyle = 'color: #EA1900'; // red + } else if (registrant.rating >= 1500 && registrant.rating <= 2199) { + registrant.colorStyle = 'color: #F2C900'; // yellow + } else if (registrant.rating >= 1200 && registrant.rating <= 1499) { + registrant.colorStyle = 'color: #4C50D9'; // blue + } else if (registrant.rating >= 900 && registrant.rating <= 1199) { + registrant.colorStyle = 'color: #258205'; // green + } + } + /* eslint-disable no-param-reassign */ + return registrant; +} + /** * Normalizes a regular challenge object received from the backend. * NOTE: This function is copied from the existing code in the challenge listing @@ -340,15 +359,11 @@ class ChallengesService { 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 = _.map(registrants, registrant => fixColorStyle(registrant)); /* Prepare data to logged user */ if (memberId) { - isRegistered = _.some(registrants, r => r.memberId === memberId); + isRegistered = _.some(registrants, r => `${r.memberId}` === `${memberId}`); const subParams = { challengeId, @@ -366,7 +381,7 @@ class ChallengesService { // Add submission date to registrants registrants.forEach((r, i) => { - const submission = submissions.find(s => s.memberId === Number(r.memberId)); + const submission = submissions.find(s => `${s.memberId}` === `${r.memberId}`); if (submission) { registrants[i].submissionDate = submission.created; } diff --git a/src/services/submissions.js b/src/services/submissions.js index 12f27021..ffdd1701 100644 --- a/src/services/submissions.js +++ b/src/services/submissions.js @@ -60,8 +60,16 @@ class SubmissionsService { const url = `/submissions?${qs.stringify(query, { encode: false })}`; return this.private.apiV5.get(url) - .then(checkErrorV5) - .then(res => res.result); + .then(res => (res.ok ? res.json() : new Error(res.statusText))) + .then((res) => { + const unique = []; + res.forEach((x) => { + if (unique.filter(a => a.updatedBy === x.updatedBy).length < 0) { + unique.push(x); + } + }); + return unique; + }); } /**