From c1383c3eecdeaf6f2306550b2358f9bb9f6c0c3a Mon Sep 17 00:00:00 2001 From: Rasmus Q Date: Sun, 29 Mar 2026 10:42:48 +0000 Subject: [PATCH] update: wishes with no link or image link should not be dismissed by zod validation --- src/lib/server/validation.ts | 10 +++++----- src/routes/wishlist/[token]/edit/+page.server.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/server/validation.ts b/src/lib/server/validation.ts index a66c325..635a183 100644 --- a/src/lib/server/validation.ts +++ b/src/lib/server/validation.ts @@ -99,17 +99,17 @@ export const currencySchema = z.enum(CURRENCIES); export const itemSchema = z.object({ title: z.string().min(1, 'Title is required').max(255), - description: z.string().max(2000).optional().nullable(), - link: z.string().url('Invalid URL').optional().nullable(), - imageUrl: z.string().url('Invalid image URL').optional().nullable(), + description: z.preprocess(val => (val === '' ? null : val), z.string().max(2000).optional().nullable()), + link: z.preprocess(val => (val === '' ? null : val), z.string().url('Invalid URL').optional().nullable()), + imageUrl: z.preprocess(val => (val === '' ? null : val), z.string().url('Invalid image URL').optional().nullable()), price: z.coerce.number().nonnegative().optional().nullable(), currency: currencySchema.default('DKK'), - color: z.string().optional().nullable(), + color: z.preprocess(val => (val === '' ? null : val), z.string().optional().nullable()), order: z.coerce.number().int().nonnegative().optional() }); export const updateItemSchema = itemSchema.extend({ - id: z.string().min(1, 'Item ID is required') + itemId: z.string().min(1, 'Item ID is required') }); export const wishlistSchema = z.object({ diff --git a/src/routes/wishlist/[token]/edit/+page.server.ts b/src/routes/wishlist/[token]/edit/+page.server.ts index 81cadec..01d9657 100644 --- a/src/routes/wishlist/[token]/edit/+page.server.ts +++ b/src/routes/wishlist/[token]/edit/+page.server.ts @@ -98,7 +98,7 @@ export const actions: Actions = { throw error(404, 'Wishlist not found'); } - const { id, ...data } = result.data; + const { itemId, ...data } = result.data; await db .update(items) .set({ @@ -106,7 +106,7 @@ export const actions: Actions = { price: data.price?.toString() || null, updatedAt: new Date() }) - .where(eq(items.id, id)); + .where(eq(items.id, itemId)); return { success: true }; },