From 0804944647ca3503edf1b1ba1487b8b037a2741b Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 11 May 2026 13:10:19 +0200 Subject: [PATCH] fix(documents): folderId=empty-string normalises to null at validator The hub UI sends folderId='' when the user picks "root-only" in the folder sidebar. The Zod validator was accepting it as a string and the service then ran eq(folderId, '') instead of isNull(folderId), returning zero results. Adding a .transform on folderId converts empty string to null at the boundary so the service receives the expected nullable shape. Pre- existing bug from Wave 11.B that the hub rebuild made more visible. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/lib/validators/documents.ts | 6 +++++- src/lib/validators/files.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/validators/documents.ts b/src/lib/validators/documents.ts index 02de6de8..dc9691f4 100644 --- a/src/lib/validators/documents.ts +++ b/src/lib/validators/documents.ts @@ -86,7 +86,11 @@ export const listDocumentsSchema = baseListQuerySchema interestId: z.string().optional(), clientId: z.string().optional(), documentType: z.string().optional(), - folderId: z.string().nullable().optional(), + folderId: z + .string() + .nullable() + .optional() + .transform((v) => (v === '' ? null : v)), includeDescendants: z.coerce.boolean().optional(), status: z.string().optional(), /** Hub tab filter - applies tab-specific status / signer-membership constraints. */ diff --git a/src/lib/validators/files.ts b/src/lib/validators/files.ts index f74f7db5..096885c5 100644 --- a/src/lib/validators/files.ts +++ b/src/lib/validators/files.ts @@ -24,7 +24,11 @@ export const listFilesSchema = baseListQuerySchema yachtId: z.string().optional(), companyId: z.string().optional(), category: z.string().optional(), - folderId: z.string().uuid().optional(), + folderId: z + .string() + .uuid() + .optional() + .transform((v) => (v === '' ? null : v)), /** Entity-aggregated projection params — mutually exclusive with folderId. */ entityType: z.enum(['client', 'company', 'yacht']).optional(), entityId: z.string().uuid().optional(),