]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/Round.js
limits for huge tournaments
[alttp.git] / resources / js / helpers / Round.js
1 import Participant from './Participant';
2 import Tournament from './Tournament';
3
4 export const isComplete = (tournament, round) => {
5         if (!tournament || !tournament.participants) return false;
6         if (!round || !round.results) return false;
7         const runners = Tournament.getRunners(tournament);
8         if (!runners.length) return false;
9         for (let i = 0; i < runners.length; ++i) {
10                 const result = Participant.findResult(runners[i], round);
11                 if (!result || !result.has_finished) return false;
12         }
13         return true;
14 };
15
16 export const patchResult = (round, result) => {
17         if (!round) return round;
18         if (!round.results || !round.results.length) {
19                 return { ...round, results: [result] };
20         }
21         if (!round.results.find(r => r.id === result.id)) {
22                 return { ...round, results: [...round.results, result] };
23         }
24         return {
25                 ...round,
26                 results: round.results.map(r => r.id === result.id ? result : r),
27         };
28 };
29
30 export default {
31         isComplete,
32         patchResult,
33 };