finished tournaments

This commit is contained in:
Torsten Schulz
2025-07-16 14:29:34 +02:00
parent d0544da1ba
commit 4122868ab0
6 changed files with 963 additions and 137 deletions

View File

@@ -57,9 +57,9 @@ export const getParticipants = async (req, res) => {
// 5. Turniermodus (Gruppen/K.O.) setzen
export const setModus = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId, type, numberOfGroups } = req.body;
const { clubId, tournamentId, type, numberOfGroups, advancingPerGroup } = req.body;
try {
await tournamentService.setModus(token, clubId, tournamentId, type, numberOfGroups);
await tournamentService.setModus(token, clubId, tournamentId, type, numberOfGroups, advancingPerGroup);
res.sendStatus(204);
} catch (error) {
console.error(error);
@@ -164,9 +164,117 @@ export const startKnockout = async (req, res) => {
try {
await tournamentService.startKnockout(token, clubId, tournamentId);
res.status(200).json({ message: 'K.O.-Runde erfolgreich gestartet' });
res.status(200).json({ message: "K.o.-Runde erfolgreich gestartet" });
} catch (error) {
console.error('Error in startKnockout:', error);
const status = /Gruppenmodus|Zu wenige Qualifikanten/.test(error.message) ? 400 : 500;
res.status(status).json({ error: error.message });
}
};
export const manualAssignGroups = async (req, res) => {
const { authcode: token } = req.headers;
const {
clubId,
tournamentId,
assignments, // [{ participantId, groupNumber }]
numberOfGroups, // optional
maxGroupSize // optional
} = req.body;
try {
const groupsWithParts = await tournamentService.manualAssignGroups(
token,
clubId,
tournamentId,
assignments,
numberOfGroups, // neu
maxGroupSize // neu
);
res.status(200).json(groupsWithParts);
} catch (error) {
console.error('Error in manualAssignGroups:', error);
res.status(500).json({ error: error.message });
}
};
export const resetGroups = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId } = req.body;
try {
await tournamentService.resetGroups(token, clubId, tournamentId);
res.sendStatus(204);
} catch (err) {
console.error(err);
res.status(500).json({ error: err.message });
}
};
export const resetMatches = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId } = req.body;
try {
await tournamentService.resetMatches(token, clubId, tournamentId);
res.sendStatus(204);
} catch (err) {
console.error(err);
res.status(500).json({ error: err.message });
}
};
export const removeParticipant = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId, participantId } = req.body;
try {
await tournamentService.removeParticipant(token, clubId, tournamentId, participantId);
const participants = await tournamentService.getParticipants(token, clubId, tournamentId);
res.status(200).json(participants);
} catch (err) {
console.error(err);
res.status(500).json({ error: err.message });
}
};
export const deleteMatchResult = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId, matchId, set } = req.body;
try {
await tournamentService.deleteMatchResult(
token,
clubId,
tournamentId,
matchId,
set
);
res.status(200).json({ message: 'Einzelsatz gelöscht' });
} catch (error) {
console.error('Error in deleteMatchResult:', error);
res.status(500).json({ error: error.message });
}
};
export const reopenMatch = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId, matchId } = req.body;
try {
await tournamentService.reopenMatch(token, clubId, tournamentId, matchId);
// Gib optional das aktualisierte Match zurück
res.status(200).json({ message: "Match reopened" });
} catch (error) {
console.error("Error in reopenMatch:", error);
res.status(500).json({ error: error.message });
}
};
export const deleteKnockoutMatches = async (req, res) => {
const { authcode: token } = req.headers;
const { clubId, tournamentId } = req.body;
try {
await tournamentService.resetKnockout(token, clubId, tournamentId);
res.status(200).json({ message: "K.o.-Runde gelöscht" });
} catch (error) {
console.error("Error in deleteKnockoutMatches:", error);
res.status(500).json({ error: error.message });
}
};