feat(official-tournaments): add venue handling and repair logic for tournament venues
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 1m2s

This commit is contained in:
Torsten Schulz (local)
2026-09-09 12:58:48 +02:00
parent bbd89c4190
commit 67ee6135d5
2 changed files with 24 additions and 34 deletions

View File

@@ -55,6 +55,17 @@ class OfficialTournamentService {
const source = new URL(sourceUrl);
if (!['www.mytischtennis.de', 'mytischtennis.de'].includes(source.hostname)) return 0;
const response = await axios.get(sourceUrl, { timeout: 30000, headers: { 'User-Agent': 'Trainingstagebuch/1.0 (+turnierdetails)' } });
const venues = this.extractJsonArray(response.data, 'tournament_locations')
.map((location) => [location.location_name, location.location_street, [location.location_zip, location.location_city].filter(Boolean).join(' ')].filter(Boolean).join(', '))
.filter(Boolean);
let repaired = 0;
if (venues.length) {
const storedVenues = JSON.parse(tournament.venues || '[]');
if (JSON.stringify(storedVenues) !== JSON.stringify(venues)) {
await tournament.update({ venues: JSON.stringify(venues) });
repaired += 1;
}
}
const competitions = this.extractJsonArray(response.data, 'competition_infos')
.filter((competition) => competition?.competition_name)
.map((competition) => ({
@@ -69,11 +80,10 @@ class OfficialTournamentService {
maxParticipants: competition.competition_player_capacity_total == null ? null : String(competition.competition_player_capacity_total),
entryFee: competition.competition_fee == null ? null : `${competition.competition_fee}${competition.competition_fee_currency === 'euro' ? '€' : ''}`,
}));
if (!competitions.length) return 0;
if (!competitions.length) return repaired;
const existing = await OfficialCompetition.findAll({ where: { tournamentId: tournament.id } });
const byName = new Map(existing.map((competition) => [this.normalizeCompetitionName(competition.ageClassCompetition), competition]));
let repaired = 0;
for (const competition of competitions) {
const existingCompetition = byName.get(this.normalizeCompetitionName(competition.ageClassCompetition));
if (existingCompetition) {
@@ -197,7 +207,9 @@ class OfficialTournamentService {
if (!t) return null;
let comps = await OfficialCompetition.findAll({ where: { tournamentId: id } });
const needsRepair = !comps.length || comps.some((competition) => !competition.startTime || competition.entryFee == null);
const venues = JSON.parse(t.venues || '[]');
const needsVenueRepair = !venues.length || venues.every((venue) => !String(venue).includes(','));
const needsRepair = needsVenueRepair || !comps.length || comps.some((competition) => !competition.startTime || competition.entryFee == null);
if (needsRepair) {
try {
await this.repairTournamentFromSource(clubId, t);