diff --git a/backend/src/db.ts b/backend/src/db.ts index a236eb0..bfbfe69 100644 --- a/backend/src/db.ts +++ b/backend/src/db.ts @@ -15,7 +15,7 @@ const poolConfig: PoolConfig = { function mockRowFromInsert(sql: string, params: unknown[]): RaceRow { const match = sql.match(/INSERT INTO races\s*\(([^)]+)\)\s*VALUES/i); - const now = new Date().toISOString(); + const now = new Date(); if (!match) { return { id: String(params[0] ?? ""), @@ -108,7 +108,7 @@ function createMockPool(): Pool { if (!existing) { return emptyResult(); } - const updated = { ...existing, updated_at: new Date().toISOString() }; + const updated = { ...existing, updated_at: new Date() }; store.set(id, updated); return { rows: [updated as unknown as T], diff --git a/backend/src/mappers/race.ts b/backend/src/mappers/race.ts index a1c22d5..cf83194 100644 --- a/backend/src/mappers/race.ts +++ b/backend/src/mappers/race.ts @@ -1,4 +1,7 @@ -/** Row shape returned by PostgreSQL (snake_case). */ +/** + * Row shape returned by PostgreSQL (snake_case). + * pg returns DATE as string, NUMERIC as string, TIMESTAMPTZ as Date. + */ export interface RaceRow { id: string; race_date: string; @@ -13,8 +16,8 @@ export interface RaceRow { finish_time: string | null; finish_place: string | null; notes: string | null; - created_at: string; - updated_at: string | null; + created_at: Date; + updated_at: Date | null; } /** API shape (camelCase). */ @@ -36,6 +39,10 @@ export interface RaceDto { updatedAt: string | null; } +function toISOString(value: Date | string): string { + return value instanceof Date ? value.toISOString() : String(value); +} + /** Convert a DB row to the API DTO (camelCase). */ export function rowToDto(row: RaceRow): RaceDto { return { @@ -52,8 +59,8 @@ export function rowToDto(row: RaceRow): RaceDto { finishTime: row.finish_time, finishPlace: row.finish_place, notes: row.notes, - createdAt: row.created_at, - updatedAt: row.updated_at, + createdAt: toISOString(row.created_at), + updatedAt: row.updated_at ? toISOString(row.updated_at) : null, }; } diff --git a/frontend/src/features/index.ts b/frontend/src/features/index.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/frontend/src/features/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {};