fix: ensure leagueId is retained when editing a team to prevent accidental removal of MyTischtennis link
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 51s

This commit is contained in:
Torsten Schulz (local)
2026-07-17 14:53:06 +02:00
parent 51b620f496
commit 7bf7ae2bef
2 changed files with 27 additions and 25 deletions

View File

@@ -250,39 +250,37 @@ class MyTischtennisUrlController {
throw new HttpError('Club team not found', 404);
}
let league;
// First, try to find existing league by name and season
const leagueName = completeData.leagueName || completeData.groupname;
league = await League.findOne({
where: {
name: leagueName,
seasonId: season.id,
clubId: team.clubId
let league;
// The league chosen for a club team is also used by the schedule filters.
// Keep that assignment and only enrich it with the MyTischtennis metadata.
if (team.leagueId) {
league = await League.findOne({
where: { id: team.leagueId, clubId: team.clubId }
});
if (league) {
devLog(`Keeping team's existing league: ${league.name} (ID: ${league.id})`);
}
});
}
if (!league) {
league = await League.findOne({
where: {
name: leagueName,
seasonId: season.id,
clubId: team.clubId
}
});
}
if (league) {
devLog(`Found existing league: ${league.name} (ID: ${league.id})`);
// Update myTischtennis fields
devLog(`Using existing league: ${league.name} (ID: ${league.id})`);
await league.update({
myTischtennisGroupId: completeData.groupId,
association: completeData.association,
groupname: completeData.groupname
});
} else if (team.leagueId) {
// Team has a league assigned, update it
league = await League.findByPk(team.leagueId);
if (league) {
devLog(`Updating team's existing league: ${league.name} (ID: ${league.id})`);
await league.update({
name: leagueName,
myTischtennisGroupId: completeData.groupId,
association: completeData.association,
groupname: completeData.groupname
});
}
} else if (createLeague) {
// Create new league
devLog(`Creating new league: ${leagueName}`);

View File

@@ -1578,12 +1578,16 @@ export default {
!!String(teamToEdit.value?.plannedLeagueName || '').trim();
const teamData = {
name: newTeamName.value.trim(),
leagueId: normalizedLeagueId,
seasonId: selectedSeasonId.value,
teamGender: newTeamGender.value,
teamAgeGroup: newTeamAgeGroup.value,
plannedLeagueName: shouldClearPlannedLeague ? null : (newPlannedLeagueName.value.trim() || null)
};
// Beim Bearbeiten darf ein leeres Auswahlfeld die bestehende Liga- und
// damit die MyTischtennis-Verknüpfung nicht versehentlich entfernen.
if (!teamToEdit.value || normalizedLeagueId) {
teamData.leagueId = normalizedLeagueId;
}
if (teamToEdit.value) {
// Bearbeitung eines bestehenden Teams