update: wishes with no link or image link should not be dismissed by zod validation

This commit is contained in:
Rasmus Q
2026-03-29 10:42:48 +00:00
parent 37870c8403
commit c1383c3eec
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -99,17 +99,17 @@ export const currencySchema = z.enum(CURRENCIES);
export const itemSchema = z.object({ export const itemSchema = z.object({
title: z.string().min(1, 'Title is required').max(255), title: z.string().min(1, 'Title is required').max(255),
description: z.string().max(2000).optional().nullable(), description: z.preprocess(val => (val === '' ? null : val), z.string().max(2000).optional().nullable()),
link: z.string().url('Invalid URL').optional().nullable(), link: z.preprocess(val => (val === '' ? null : val), z.string().url('Invalid URL').optional().nullable()),
imageUrl: z.string().url('Invalid image 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(), price: z.coerce.number().nonnegative().optional().nullable(),
currency: currencySchema.default('DKK'), 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() order: z.coerce.number().int().nonnegative().optional()
}); });
export const updateItemSchema = itemSchema.extend({ 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({ export const wishlistSchema = z.object({
@@ -98,7 +98,7 @@ export const actions: Actions = {
throw error(404, 'Wishlist not found'); throw error(404, 'Wishlist not found');
} }
const { id, ...data } = result.data; const { itemId, ...data } = result.data;
await db await db
.update(items) .update(items)
.set({ .set({
@@ -106,7 +106,7 @@ export const actions: Actions = {
price: data.price?.toString() || null, price: data.price?.toString() || null,
updatedAt: new Date() updatedAt: new Date()
}) })
.where(eq(items.id, id)); .where(eq(items.id, itemId));
return { success: true }; return { success: true };
}, },