]> git.localhorst.tv Git - alttp.git/blob - resources/js/helpers/Tournament.js
1b808fdf3211f8eede21ee009defb1043db3d4d6
[alttp.git] / resources / js / helpers / Tournament.js
1 import Round from './Round';
2
3 export const findParticipant = (tournament, user) => {
4         if (!tournament || !tournament.participants || !tournament.participants.length) return null;
5         if (!user || !user.id) return null;
6         return tournament.participants.find(p => p.user_id == user.id);
7 };
8
9 export const patchResult = (tournament, result) => {
10         if (!tournament || !tournament.rounds) return tournament;
11         return {
12                 ...tournament,
13                 rounds: tournament.rounds.map(round =>
14                         round.id === result.round_id
15                                 ? Round.patchResult(round, result)
16                                 : round
17                 ),
18         };
19 };
20
21 export default {
22         findParticipant,
23         patchResult,
24 };