feat(official-tournaments): implement reimport functionality for official tournaments
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 57s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 57s
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user