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.
This commit is contained in:
Torsten Schulz (local)
2026-01-30 23:16:00 +01:00
parent 47a815dd71
commit 28db204aba

View File

@@ -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;
}
}