fix: improve existing match handling in CSV import to ensure correct league and location updates
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 50s

This commit is contained in:
Torsten Schulz (local)
2026-07-17 15:19:23 +02:00
parent 7bf7ae2bef
commit 6afa5a5629

View File

@@ -185,25 +185,12 @@ class MatchService {
});
}
// Club teams already configured through MyTischtennis can be linked to
// leagues with a different display name than the click-TT CSV "Staffel".
// Update the existing match in that league so the schedule view receives
// the venue instead of creating a disconnected duplicate in a CSV league.
const existingMatch = await this.findExistingMatchForCSV(
clubId,
parsedDate,
homeTeamName,
guestTeamName
);
if (existingMatch) {
if (location && existingMatch.locationId !== location.id) {
await existingMatch.update({ locationId: location.id });
}
continue;
}
// Resolve the CSV teams before looking for a previous import. A match may
// already exist in a legacy/generic league (for example "1. Kreisklasse"),
// while this CSV supplies the actual youth league. In that case it must be
// moved to the CSV league as well, otherwise it is classified as adult.
const homeTeamId = await this.getOrCreateTeamId(
row['HeimMannschaft'],
row['HeimMannschaft'],
row['HeimMannschaftAltersklasse'],
clubId,
league.id,
@@ -216,6 +203,28 @@ class MatchService {
league.id,
season.id
);
const existingMatch = await this.findExistingMatchForCSV(
clubId,
parsedDate,
homeTeamName,
guestTeamName
);
if (existingMatch) {
const updates = {};
if (location && existingMatch.locationId !== location.id) {
updates.locationId = location.id;
}
if (existingMatch.leagueId !== league.id) {
updates.leagueId = league.id;
updates.homeTeamId = homeTeamId;
updates.guestTeamId = guestTeamId;
}
if (Object.keys(updates).length > 0) {
await existingMatch.update(updates);
}
continue;
}
matches.push({
date: parsedDate,
time: row['Termin'].split(' ')[1],