fix(library): create the match without waiting on the inbox (BIT-184) #184
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user