update: wishes with no link or image link should not be dismissed by zod validation
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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 };
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user