From 13cd55c051fb10fa60cb96adcd96773e87f34986 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 17 Dec 2025 08:45:52 +0100 Subject: [PATCH] feat(tournament): validate tournament members and load external participants - Added logic to check if loaded TournamentMembers belong to the current tournament, setting them to null if not. - Updated filtering for external participant IDs to ensure only valid IDs are processed for matches with null players. --- backend/services/tournamentService.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backend/services/tournamentService.js b/backend/services/tournamentService.js index 04f41dd..6faae16 100644 --- a/backend/services/tournamentService.js +++ b/backend/services/tournamentService.js @@ -1726,9 +1726,20 @@ class TournamentService { return (a.id ?? 0) - (b.id ?? 0); }); + // WICHTIG: Prüfe, ob die geladenen TournamentMember tatsächlich zu diesem Turnier gehören + // Wenn nicht, setze sie auf null, damit sie als externe Teilnehmer geladen werden können + matches.forEach(match => { + if (match.player1 && match.player1.tournamentId !== tournamentId) { + match.player1 = null; + } + if (match.player2 && match.player2.tournamentId !== tournamentId) { + match.player2 = null; + } + }); + // Lade externe Teilnehmer für Matches, bei denen player1 oder player2 null ist - const player1Ids = matches.filter(m => !m.player1).map(m => m.player1Id); - const player2Ids = matches.filter(m => !m.player2).map(m => m.player2Id); + const player1Ids = matches.filter(m => !m.player1 && m.player1Id).map(m => m.player1Id); + const player2Ids = matches.filter(m => !m.player2 && m.player2Id).map(m => m.player2Id); const externalPlayerIds = [...new Set([...player1Ids, ...player2Ids])]; if (externalPlayerIds.length > 0) {