From f4be3ee90187a35210bad8fc9b8c485f3be04055 Mon Sep 17 00:00:00 2001 From: Mitchell R Date: Tue, 26 May 2026 01:54:08 +0200 Subject: [PATCH] fix(db): handle PG Date objects in string mappers PG driver returns TIMESTAMPTZ as JS Date objects. The s() and sn() mapper helpers only checked for typeof string, returning null/empty for Date objects. This broke consumed_at check in pairing (always null), expires_at comparisons (Invalid Date), and all other timestamp fields. Now: Date instances are converted to ISO strings via toISOString(). Co-Authored-By: Claude Opus 4.6 (1M context) --- server/src/shared/db/mappers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/shared/db/mappers.ts b/server/src/shared/db/mappers.ts index 111fc42..bfae32a 100644 --- a/server/src/shared/db/mappers.ts +++ b/server/src/shared/db/mappers.ts @@ -59,8 +59,8 @@ import { b, j } from "./util.js"; type Row = Record; -const s = (v: unknown): string => (typeof v === "string" ? v : ""); -const sn = (v: unknown): string | null => (typeof v === "string" ? v : null); +const s = (v: unknown): string => (typeof v === "string" ? v : v instanceof Date ? v.toISOString() : String(v ?? "")); +const sn = (v: unknown): string | null => (v == null ? null : typeof v === "string" ? v : v instanceof Date ? v.toISOString() : null); const n = (v: unknown): number => (typeof v === "number" ? v : Number(v) || 0); const nn = (v: unknown): number | null => v === null || v === undefined ? null : typeof v === "number" ? v : Number(v) || null;