feat(official-tournaments): implement reimport functionality for official tournaments
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 57s

This commit is contained in:
Torsten Schulz (local)
2026-09-09 13:16:04 +02:00
parent 0c9a898d61
commit ab4d99192e
4 changed files with 43 additions and 1 deletions

View File

@@ -16,6 +16,20 @@ export const saveTournamentSuggestion = async (req, res) => {
}
};
export const reimportOfficialTournament = async (req, res) => {
try {
const { authcode: userToken } = req.headers;
const { clubId, id } = req.params;
await checkAccess(userToken, clubId);
const result = await officialTournamentService.reimportOfficialTournament(clubId, id);
if (!result) return res.status(404).json({ error: 'Turnier nicht gefunden.' });
return res.json(result);
} catch (error) {
console.error('[reimportOfficialTournament] Error:', error);
return res.status(error.status || 500).json({ error: error.message || 'Turnierdaten konnten nicht aktualisiert werden.' });
}
};
export const updateOfficialTournament = async (req, res) => {
try {
const { authcode: userToken } = req.headers;

View File

@@ -11,7 +11,7 @@ import {
listClubParticipations,
updateParticipantStatus,
autoRegisterOfficialTournamentParticipants
, listTacticPlans, saveTacticPlan, deleteTacticPlan, saveTournamentSuggestion
, listTacticPlans, saveTacticPlan, deleteTacticPlan, saveTournamentSuggestion, reimportOfficialTournament
} from '../controllers/officialTournamentController.js';
import { fetchTournamentSuggestions, listTournamentSuggestions, updateTournamentSuggestion } from '../controllers/tournamentSuggestionController.js';
@@ -31,6 +31,7 @@ router.get('/:clubId/:tournamentId/tactics', listTacticPlans);
router.post('/:clubId/:tournamentId/tactics', saveTacticPlan);
router.patch('/:clubId/:tournamentId/tactics/:planId', saveTacticPlan);
router.delete('/:clubId/:tournamentId/tactics/:planId', deleteTacticPlan);
router.post('/:clubId/:id/reimport', reimportOfficialTournament);
router.get('/:clubId/:id', getParsedTournament);
router.patch('/:clubId/:id', updateOfficialTournament);
router.delete('/:clubId/:id', deleteOfficialTournament);

View File

@@ -96,6 +96,18 @@ class OfficialTournamentService {
return repaired;
}
async reimportOfficialTournament(clubId, tournamentId) {
const tournament = await OfficialTournament.findOne({ where: { id: tournamentId, clubId } });
if (!tournament) return null;
const updatedCount = await this.repairTournamentFromSource(clubId, tournament);
if (!tournament.sourceUrl) {
const error = new Error('Für dieses Turnier ist keine myTischtennis-Quelle hinterlegt.');
error.status = 400;
throw error;
}
return { id: String(tournament.id), updatedCount };
}
async saveTournamentSuggestion(clubId, suggestionId) {
const suggestion = await TournamentSuggestion.findOne({ where: { id: suggestionId, clubId } });
if (!suggestion) return null;