1 export const comparePlacement = (a, b) => {
2 if (a.placement < b.placement) return -1;
3 if (b.placement < a.placement) return 1;
4 return compareUsername(a, b);
7 export const compareResult = round => (a, b) => {
8 const a_result = findResult(a, round);
9 const b_result = findResult(b, round);
10 const a_placement = a_result && a_result.placement ? a_result.placement : 0;
11 const b_placement = b_result && b_result.placement ? b_result.placement : 0;
14 if (a_placement < b_placement) return -1;
15 if (b_placement < a_placement) return 1;
16 return compareUsername(a, b);
23 return compareUsername(a, b);
26 export const compareUsername = (a, b) => {
27 const a_name = a && a.user && a.user.username ? a.user.username : '';
28 const b_name = b && b.user && b.user.username ? b.user.username : '';
29 return a_name.localeCompare(b_name);
32 export const findResult = (participant, round) => {
33 if (!participant || !participant.user_id) return null;
34 if (!round || !round.results || !round.results.length) return null;
35 return round.results.find(result => result.user_id === participant.user_id);
38 export const isRunner = participant =>
39 participant && participant.roles && participant.roles.includes('runner');
41 export const isTournamentAdmin = participant =>
42 participant && participant.roles && participant.roles.includes('admin');
44 export const isTournamentCrew = participant =>
45 isTournamentAdmin(participant) || isTournamentMonitor(participant);
47 export const isTournamentMonitor = participant =>
48 participant && participant.roles && participant.roles.includes('monitor');
50 export const patchUser = (participant, user) => {
51 if (!participant || !user) return participant;
52 if (participant.user_id != user.id) return participant;
62 export const sortByResult = (participants, round) => {
63 if (!participants || !participants.length) return participants;
64 if (!round || !round.results || !round.results.length) return participants;
65 return participants.sort(compareResult(round));