From 28db204abad2601eb6043d95c81e77d2ac437104 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 30 Jan 2026 23:16:00 +0100 Subject: [PATCH] refactor(tournament): simplify tournament creation by removing duplicate checks - Removed duplicate tournament existence checks from the addTournament method, streamlining the tournament creation process. - Enhanced error handling to provide clearer messages related to database migration requirements for mini championships. --- backend/services/tournamentService.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/services/tournamentService.js b/backend/services/tournamentService.js index 82e7694..4411bc8 100644 --- a/backend/services/tournamentService.js +++ b/backend/services/tournamentService.js @@ -695,13 +695,9 @@ class TournamentService { return JSON.parse(JSON.stringify(tournaments)); } - // 2. Neues Turnier anlegen (prüft Duplikat) + // 2. Neues Turnier anlegen async addTournament(userToken, clubId, tournamentName, date, winningSets, allowsExternal) { await checkAccess(userToken, clubId); - const existing = await Tournament.findOne({ where: { clubId, date } }); - if (existing) { - throw new Error('Ein Turnier mit diesem Datum existiert bereits'); - } const t = await Tournament.create({ name: tournamentName, date, @@ -726,10 +722,6 @@ class TournamentService { if (!ortTrimmed) { throw new Error('Ort für die Minimeisterschaft fehlt'); } - const existing = await Tournament.findOne({ where: { clubId, date } }); - if (existing) { - throw new Error('Ein Turnier mit diesem Datum existiert bereits'); - } const Y = Number(year); if (!Number.isFinite(Y) || Y < 2000 || Y > 2100) { throw new Error('Ungültiges Jahr für die Minimeisterschaft'); @@ -776,6 +768,10 @@ class TournamentService { }))); } catch (err) { await transaction.rollback(); + const msg = err?.message || String(err); + if (msg.includes('max_birth_year') || msg.includes('Unknown column')) { + throw new Error('Datenbank-Migration für Minimeisterschaften fehlt. Bitte die Migration 20260130_add_mini_championship_and_max_birth_year.sql ausführen.'); + } throw err; } }