X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FParticipant.js;h=4b4b6ef51c5ee0cb72a73b9ddaca50e2d2321e1a;hb=a748d5724c8acff6e3bb3fe6c20aa5968b65d58a;hp=eb943401f6074057b4e6fc625c0d7385c4d15042;hpb=920f11ddfeb2175e4e1556886773dcd044c6085b;p=alttp.git diff --git a/resources/js/helpers/Participant.js b/resources/js/helpers/Participant.js index eb94340..4b4b6ef 100644 --- a/resources/js/helpers/Participant.js +++ b/resources/js/helpers/Participant.js @@ -1,28 +1,23 @@ +export const comparePlacement = (a, b) => { + if (a.placement < b.placement) return -1; + if (b.placement < a.placement) return 1; + return compareUsername(a, b); +}; + export const compareResult = round => (a, b) => { const a_result = findResult(a, round); const b_result = findResult(b, round); - const a_time = a_result && !a_result.forfeit ? a_result.time : 0; - const b_time = b_result && !b_result.forfeit ? b_result.time : 0; - if (a_time) { - if (b_time) { - if (a_time < b_time) return -1; - if (b_time < a_time) return 1; - return 0; - } - return -1; - } - if (b_time) { - return 1; - } - const a_forfeit = a_result && a_result.forfeit; - const b_forfeit = b_result && b_result.forfeit; - if (a_forfeit) { - if (b_forfeit) { - return 0; + const a_placement = a_result && a_result.placement ? a_result.placement : 0; + const b_placement = b_result && b_result.placement ? b_result.placement : 0; + if (a_placement) { + if (b_placement) { + if (a_placement < b_placement) return -1; + if (b_placement < a_placement) return 1; + return compareUsername(a, b); } return -1; } - if (b_forfeit) { + if (b_placement) { return 1; } return compareUsername(a, b); @@ -40,6 +35,18 @@ export const findResult = (participant, round) => { return round.results.find(result => result.user_id === participant.user_id); }; +export const isRunner = participant => + participant && participant.roles && participant.roles.includes('runner'); + +export const isTournamentAdmin = participant => + participant && participant.roles && participant.roles.includes('admin'); + +export const isTournamentCrew = participant => + isTournamentAdmin(participant) || isTournamentMonitor(participant); + +export const isTournamentMonitor = participant => + participant && participant.roles && participant.roles.includes('monitor'); + export const patchUser = (participant, user) => { if (!participant || !user) return participant; if (participant.user_id != user.id) return participant; @@ -62,6 +69,10 @@ export default { compareResult, compareUsername, findResult, + isRunner, + isTournamentAdmin, + isTournamentCrew, + isTournamentMonitor, patchUser, sortByResult, };