feat(tournament): add mini championship functionality and enhance tournament class handling

- Introduced addMiniChampionship method in tournamentService to create tournaments with predefined classes for mini championships.
- Updated getTournaments method to filter tournaments based on type, including support for mini championships.
- Enhanced TournamentClass model to include maxBirthYear for age class restrictions.
- Modified tournamentController and tournamentRoutes to support new mini championship endpoint.
- Updated frontend components to manage mini championship creation and display, including localization for new terms.
This commit is contained in:
Torsten Schulz (local)
2026-01-30 22:58:41 +01:00
parent 6cdcbfe0db
commit 85c26bc80d
10 changed files with 265 additions and 104 deletions

View File

@@ -40,12 +40,13 @@ export const resetPool = async (req, res) => {
}
};
// 1. Alle Turniere eines Vereins
// 1. Alle Turniere eines Vereins (query: type = 'internal' | 'external' | 'mini')
export const getTournaments = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId } = req.params;
const type = req.query.type || null;
try {
const tournaments = await tournamentService.getTournaments(token, clubId);
const tournaments = await tournamentService.getTournaments(token, clubId, type);
res.status(200).json(tournaments);
} catch (error) {
console.error(error);
@@ -64,7 +65,6 @@ export const addTournament = async (req, res) => {
const { clubId, tournamentName, date, winningSets, allowsExternal } = req.body;
try {
const tournament = await tournamentService.addTournament(token, clubId, tournamentName, date, winningSets, allowsExternal);
// Emit Socket-Event
if (clubId && tournament && tournament.id) {
emitTournamentChanged(clubId, tournament.id);
}
@@ -75,6 +75,22 @@ export const addTournament = async (req, res) => {
}
};
// Minimeisterschaft anlegen (Turnier + 6 Klassen)
export const addMiniChampionship = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentName, date, year, winningSets } = req.body;
try {
const tournament = await tournamentService.addMiniChampionship(token, clubId, tournamentName, date, year, winningSets);
if (clubId && tournament && tournament.id) {
emitTournamentChanged(clubId, tournament.id);
}
res.status(201).json(tournament);
} catch (error) {
console.error('[addMiniChampionship] Error:', error);
res.status(500).json({ error: error.message });
}
};
// 3. Teilnehmer hinzufügen - klassengebunden
export const addParticipant = async (req, res) => {
const { authcode: token } = req.headers;
@@ -599,9 +615,9 @@ export const getTournamentClasses = async (req, res) => {
export const addTournamentClass = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId } = req.params;
const { name, isDoubles, gender, minBirthYear } = req.body;
const { name, isDoubles, gender, minBirthYear, maxBirthYear } = req.body;
try {
const tournamentClass = await tournamentService.addTournamentClass(token, clubId, tournamentId, name, isDoubles, gender, minBirthYear);
const tournamentClass = await tournamentService.addTournamentClass(token, clubId, tournamentId, name, isDoubles, gender, minBirthYear, maxBirthYear);
emitTournamentChanged(clubId, tournamentId);
res.status(200).json(tournamentClass);
} catch (error) {
@@ -613,11 +629,9 @@ export const addTournamentClass = async (req, res) => {
export const updateTournamentClass = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId, classId } = req.params;
const { name, sortOrder, isDoubles, gender, minBirthYear } = req.body;
const { name, sortOrder, isDoubles, gender, minBirthYear, maxBirthYear } = req.body;
try {
console.log('[updateTournamentClass] Request body:', { name, sortOrder, isDoubles, gender, minBirthYear });
const tournamentClass = await tournamentService.updateTournamentClass(token, clubId, tournamentId, classId, name, sortOrder, isDoubles, gender, minBirthYear);
console.log('[updateTournamentClass] Updated class:', JSON.stringify(tournamentClass.toJSON(), null, 2));
const tournamentClass = await tournamentService.updateTournamentClass(token, clubId, tournamentId, classId, name, sortOrder, isDoubles, gender, minBirthYear, maxBirthYear);
emitTournamentChanged(clubId, tournamentId);
res.status(200).json(tournamentClass);
} catch (error) {