From d12b9daf876607b20d3342df9549e5f3dba40a7c Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Sat, 31 Jan 2026 00:08:25 +0100 Subject: [PATCH] fix(tournament): remove matches for participants before deletion - Added logic to delete all matches associated with a participant before their removal from the tournament, ensuring data integrity and preventing orphaned match records. --- backend/services/tournamentService.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/services/tournamentService.js b/backend/services/tournamentService.js index 3d8d7da..24828ec 100644 --- a/backend/services/tournamentService.js +++ b/backend/services/tournamentService.js @@ -3380,6 +3380,16 @@ Ve // 2. Neues Turnier anlegen if (!participant) { throw new Error('Externer Teilnehmer nicht gefunden'); } + // Lösche alle Matches, in denen dieser Teilnehmer spielt + await TournamentMatch.destroy({ + where: { + tournamentId, + [Op.or]: [ + { player1Id: participantId }, + { player2Id: participantId } + ] + } + }); await participant.destroy(); }