From 22dda8726eaf2dc0338bc8c7c319dfc2e3e708f2 Mon Sep 17 00:00:00 2001 From: spark Date: Mon, 19 Oct 2026 03:44:15 +0100 Subject: [PATCH] Keep a Liga game in the season Liga named, never the season we asked for. A fixture id is updated in place. Writing a season the calendar did not stamp would move that game into another year. --- apps/api/src/sports/providers.ts | 6 +++++- apps/api/src/sports/service.ts | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/api/src/sports/providers.ts b/apps/api/src/sports/providers.ts index 1f371de..effae12 100644 --- a/apps/api/src/sports/providers.ts +++ b/apps/api/src/sports/providers.ts @@ -42,6 +42,8 @@ export interface FixtureData { competitionName?: string; gender?: string | null; season: string; + /** Liga named this season on the fixture. Absent means the caller asked for a season and Liga did not confirm it. */ + seasonNamed?: boolean; home: TeamData; away: TeamData; startsAt: Date; @@ -229,11 +231,13 @@ export class LigaProvider { if (!comp || !home || !away || !when || f.canceledFixture) continue; const code = str(f.fixtureCode) ?? `${f.round ?? f.matchweekNumber}-${home.externalId}-${away.externalId}`; const finished = typeof f.fixtureStateTypeId === "number" && f.fixtureStateTypeId >= 5; + const named = str(f.seasonCode); out.push({ externalId: code, competition: comp.externalId, competitionName: comp.name, - season: str(f.seasonCode) ?? season, + season: named ?? season, + seasonNamed: named !== null, home, away, startsAt: new Date(when), diff --git a/apps/api/src/sports/service.ts b/apps/api/src/sports/service.ts index 4fd4e2b..0823f72 100644 --- a/apps/api/src/sports/service.ts +++ b/apps/api/src/sports/service.ts @@ -167,10 +167,13 @@ export class SportsService { for (const f of await this.liga.month(month, season)) { // A month can answer with another season's games. Those keep the season Liga named, never this one: // the same fixture id updated in place would move a game out of the season it belongs to. - const theirs = (f.season ?? "").replace(/\D/g, ""); - if (theirs && theirs !== asked) continue; + // Only a season Liga itself named. Guessing the season we asked for would move another year's game + // onto this one, because the fixture id is updated in place. + if (!f.seasonNamed) continue; + const theirs = f.season.replace(/\D/g, ""); + if (theirs !== asked) continue; const c = byExternal.get(f.competition); - if (c) saved += await this.saveFixture(c, "LIGA", { ...f, season: asked }); + if (c) saved += await this.saveFixture(c, "LIGA", f); } } this.deps.log.info({ season, saved }, "sports: liga season imported"); -- 2.47.3