diff --git a/apps/api/src/sports/service.ts b/apps/api/src/sports/service.ts index d030731..4fd4e2b 100644 --- a/apps/api/src/sports/service.ts +++ b/apps/api/src/sports/service.ts @@ -161,11 +161,16 @@ export class SportsService { async importLigaSeason(season: string): Promise { const comps = await this.deps.db.sportsCompetition.findMany({ where: { provider: "LIGA" } }); const byExternal = new Map(comps.map((c) => [c.externalId, c])); + const asked = season.replace(/\D/g, ""); let saved = 0; for (const month of [7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6]) { 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; const c = byExternal.get(f.competition); - if (c) saved += await this.saveFixture(c, "LIGA", { ...f, season }); + if (c) saved += await this.saveFixture(c, "LIGA", { ...f, season: asked }); } } this.deps.log.info({ season, saved }, "sports: liga season imported");