]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/Round.js
tournament admins
[alttp.git] / resources / js / helpers / Round.js
1 export const isComplete = (tournament, round) => {
2         if (!tournament || !tournament.participants) return false;
3         if (!round || !round.results) return false;
4         return tournament.participants.length === round.results.length &&
5                 round.results.filter(r => !r.has_finished).length === 0;
6 };
7
8 export const patchResult = (round, result) => {
9         if (!round) return round;
10         if (!round.results || !round.results.length) {
11                 return { ...round, results: [result] };
12         }
13         if (!round.results.find(r => r.id === result.id)) {
14                 return { ...round, results: [...round.results, result] };
15         }
16         return {
17                 ...round,
18                 results: round.results.map(r => r.id === result.id ? result : r),
19         };
20 };
21
22 export default {
23         isComplete,
24         patchResult,
25 };