]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/Tournament.js
result reporting
[alttp.git] / resources / js / helpers / Tournament.js
diff --git a/resources/js/helpers/Tournament.js b/resources/js/helpers/Tournament.js
new file mode 100644 (file)
index 0000000..1b808fd
--- /dev/null
@@ -0,0 +1,24 @@
+import Round from './Round';
+
+export const findParticipant = (tournament, user) => {
+       if (!tournament || !tournament.participants || !tournament.participants.length) return null;
+       if (!user || !user.id) return null;
+       return tournament.participants.find(p => p.user_id == user.id);
+};
+
+export const patchResult = (tournament, result) => {
+       if (!tournament || !tournament.rounds) return tournament;
+       return {
+               ...tournament,
+               rounds: tournament.rounds.map(round =>
+                       round.id === result.round_id
+                               ? Round.patchResult(round, result)
+                               : round
+               ),
+       };
+};
+
+export default {
+       findParticipant,
+       patchResult,
+};