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.
This commit is contained in:
Torsten Schulz (local)
2025-12-17 08:45:52 +01:00
parent 9bf37399d5
commit 13cd55c051

View File

@@ -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) {