feat: add team name normalization for club matching in match service
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 51s

This commit is contained in:
Torsten Schulz (local)
2026-07-17 15:35:57 +02:00
parent 6afa5a5629
commit 110519c7b8

View File

@@ -79,6 +79,26 @@ class MatchService {
.trim();
}
isTeamNameForClub(teamName, clubName) {
const normalize = (name) => String(name || '')
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
// Vereinsnamen im click-TT-Export enthalten teils eine Jahreszahl,
// die im hinterlegten Vereinsnamen fehlt (z. B. TSV Bonames / TSV 1875 Bonames).
.replace(/\b\d+\b/g, ' ')
.replace(/[^\p{L}]+/gu, ' ')
.replace(/\s+/g, ' ')
.trim();
const normalizedClubName = normalize(clubName);
const normalizedTeamName = normalize(teamName);
return Boolean(normalizedClubName) && (
normalizedTeamName === normalizedClubName ||
normalizedTeamName.startsWith(`${normalizedClubName} `)
);
}
getAgeGroupCode(ageClass) {
const match = String(ageClass || '').match(/jugend\s+(\d+)/i);
return match ? `J${match[1]}` : null;
@@ -333,14 +353,13 @@ class MatchService {
const leagueIdList = leaguesInSeason.map((l) => l.id);
let ownTeamIdSet = new Set();
if (club?.name && leagueIdList.length) {
const escaped = String(club.name).replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_');
const ownTeams = await Team.findAll({
where: {
leagueId: { [Op.in]: leagueIdList },
name: { [Op.like]: `${escaped}%` }
},
attributes: ['id']
const teamsInSeason = await Team.findAll({
where: { leagueId: { [Op.in]: leagueIdList } },
attributes: ['id', 'name']
});
const ownTeams = teamsInSeason.filter((team) =>
this.isTeamNameForClub(team.name, club.name)
);
ownTeamIdSet = new Set(ownTeams.map((t) => t.id));
}
@@ -437,17 +456,13 @@ class MatchService {
}
});
} else {
const clubName = club.name;
const ownTeams = await Team.findAll({
where: {
name: {
[Op.like]: `${clubName}%`
},
leagueId: leagueId
},
const teamsInLeague = await Team.findAll({
where: { leagueId: leagueId },
attributes: ['id', 'name']
});
const ownTeams = teamsInLeague.filter((team) =>
this.isTeamNameForClub(team.name, club.name)
);
const ownTeamIds = ownTeams.map(t => t.id);