From d37d763376955bb319e36b42c36125f83f466b22 Mon Sep 17 00:00:00 2001 From: spark Date: Wed, 4 Nov 2026 15:34:35 +0000 Subject: [PATCH 1/2] fix(library): return the new event without waiting on the inbox Creating a match failed in the form when the answer never came back as JSON. The event is saved first. Photos already in the inbox are attached afterwards, and a second click on the same game reuses the event. --- apps/api/src/library/events.ts | 10 ++++++++-- apps/app/src/library/EventForm.tsx | 16 +++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/apps/api/src/library/events.ts b/apps/api/src/library/events.ts index e82d2f0..26cec4a 100644 --- a/apps/api/src/library/events.ts +++ b/apps/api/src/library/events.ts @@ -173,6 +173,11 @@ export async function registerEventRoutes(app: FastifyInstance, deps: { db: Db; if (body.photographerIds?.length) await assertMembers(orgId, body.photographerIds); const { photographerIds, iptcTemplate, ingestFrom, ingestUntil, autopilot, fixtureId, homeTeamId, awayTeamId, ...fields } = body; const match = await resolveMatch({ fixtureId, homeTeamId, awayTeamId }); + // A second click (the first answer never arrived) must not create the game twice. + if (match.fixtureId) { + const existing = await db.event.findFirst({ where: { organizationId: orgId, fixtureId: match.fixtureId, archivedAt: null }, include, orderBy: { createdAt: "asc" } }); + if (existing) return reply.code(200).send(serialize(existing)); + } // Fall back to the federation's official short codes when the fixture carried none (handball has no abbreviations). const homeShort = fields.homeShort ?? officialSigla(fields.home); const awayShort = fields.awayShort ?? (fields.away ? officialSigla(fields.away) : undefined); @@ -195,8 +200,9 @@ export async function registerEventRoutes(app: FastifyInstance, deps: { db: Db; include, }); if (event.homeTeamId || event.awayTeamId) syncSquads(event.id); - await claim(orgId, event.id); - return reply.code(201).send(serialize(await db.event.findUniqueOrThrow({ where: { id: event.id }, include }))); + // Claiming the inbox can scan a large library. The event already exists; the answer must not wait on it. + void claim(orgId, event.id); + return reply.code(201).send(serialize(event)); }); app.get("/v1/events/:eventId", { preHandler: authenticate }, async (req) => { diff --git a/apps/app/src/library/EventForm.tsx b/apps/app/src/library/EventForm.tsx index 0007d1e..0fc94e3 100644 --- a/apps/app/src/library/EventForm.tsx +++ b/apps/app/src/library/EventForm.tsx @@ -5,10 +5,14 @@ import { t } from "../i18n.js"; /** Lisbon wall-clock "YYYY-MM-DDTHH:mm" (datetime-local) → ISO instant. */ export function lisbonLocalToIso(local: string): string { - const [date, time] = local.split("T"); - const [y, m, d] = (date ?? "").split("-").map(Number); - const [hh, mm] = (time ?? "").split(":").map(Number); - const wall = Date.UTC(y!, m! - 1, d!, hh!, mm!); + const match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(local.trim()); + if (!match) throw new Error("invalid_start"); + const y = Number(match[1]); + const m = Number(match[2]); + const d = Number(match[3]); + const hh = Number(match[4]); + const mm = Number(match[5]); + const wall = Date.UTC(y, m - 1, d, hh, mm); const offset = (at: number) => { const p = Object.fromEntries( new Intl.DateTimeFormat("en-US", { timeZone: "Europe/Lisbon", hourCycle: "h23", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }) @@ -119,7 +123,9 @@ export function EventForm({ api, orgId, onClose, onCreated }: { api: ApiClient; }); onCreated(event); } catch (err) { - setError(err instanceof ApiError ? err.code : t.unexpectedError); + const code = err instanceof ApiError ? err.code : err instanceof Error ? err.message : ""; + const detail = err instanceof ApiError && err.body && typeof err.body === "object" && "message" in err.body ? String((err.body as { message?: unknown }).message ?? "") : ""; + setError(code === "invalid_start" ? "A hora de início não é válida." : detail && detail !== code ? detail : code || t.unexpectedError); } finally { setBusy(false); } -- 2.47.3 From 850c65c0d9cd15f5b3046874c4d39140cd298d92 Mon Sep 17 00:00:00 2001 From: spark Date: Wed, 4 Nov 2026 15:43:25 +0000 Subject: [PATCH 2/2] fix(library): reuse an official game that was already created A second click returns the event instead of waiting again. The first create still claims inbox photos before it answers. --- apps/api/src/library/events.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/api/src/library/events.ts b/apps/api/src/library/events.ts index 26cec4a..742d7cb 100644 --- a/apps/api/src/library/events.ts +++ b/apps/api/src/library/events.ts @@ -200,9 +200,8 @@ export async function registerEventRoutes(app: FastifyInstance, deps: { db: Db; include, }); if (event.homeTeamId || event.awayTeamId) syncSquads(event.id); - // Claiming the inbox can scan a large library. The event already exists; the answer must not wait on it. - void claim(orgId, event.id); - return reply.code(201).send(serialize(event)); + await claim(orgId, event.id); + return reply.code(201).send(serialize(await db.event.findUniqueOrThrow({ where: { id: event.id }, include }))); }); app.get("/v1/events/:eventId", { preHandler: authenticate }, async (req) => { -- 2.47.3