|
1 | 1 | import { z } from 'zod'; |
2 | 2 |
|
3 | | -// Category schema |
| 3 | +// Simple category schema for forms |
4 | 4 | export const categorySchema = z.object({ |
5 | | - name: z |
6 | | - .string() |
7 | | - .min(1, 'Category name is required') |
8 | | - .max(100, 'Category name must be 100 characters or less'), |
9 | | - description: z.string().max(500, 'Description must be 500 characters or less'), |
10 | | - parentId: z.string().optional() |
11 | | -}); |
12 | | - |
13 | | -export const updateCategorySchema = categorySchema |
14 | | - .extend({ |
15 | | - name: z |
16 | | - .string() |
17 | | - .min(1, 'Category name is required') |
18 | | - .max(100, 'Category name must be 100 characters or less'), |
19 | | - description: z.string().max(500, 'Description must be 500 characters or less').optional(), |
20 | | - parentId: z.string() |
21 | | - }) |
22 | | - .partial() |
23 | | - .refine((data) => { |
24 | | - // Ensure at least one field is provided for update |
25 | | - return data.name || data.description || data.parentId !== undefined; |
26 | | - }); |
27 | | - |
28 | | -// Discount schema |
29 | | -export const discountSchema = z.object({ |
30 | | - code: z |
31 | | - .string() |
32 | | - .min(1, 'Discount code is required') |
33 | | - .transform((val) => val.toUpperCase()), |
| 5 | + name: z.string().min(1, 'Category name is required').max(100), |
34 | 6 | description: z.string().optional(), |
35 | | - type: z.enum(['percentage', 'fixed'], { required_error: 'Discount type is required' }), |
36 | | - method: z.enum(['basket', 'product'], { required_error: 'Discount method is required' }), |
37 | | - value: z.number().min(0, 'Value must be 0 or greater'), |
38 | | - minimumOrderAmount: z.number().min(0, 'Minimum order amount must be 0 or greater').optional(), |
39 | | - usageLimit: z.number().int().min(1, 'Usage limit must be at least 1').optional(), |
40 | | - expiresAt: z.string().optional(), |
41 | | - isActive: z.boolean().default(true) |
42 | | -}); |
43 | | - |
44 | | -// Currency schema |
45 | | -export const currencySchema = z.object({ |
46 | | - code: z |
47 | | - .string() |
48 | | - .min(3, 'Currency code must be 3 characters') |
49 | | - .max(3, 'Currency code must be 3 characters') |
50 | | - .transform((val) => val.toUpperCase()), |
51 | | - name: z.string().min(1, 'Currency name is required'), |
52 | | - symbol: z.string().min(1, 'Currency symbol is required'), |
53 | | - exchangeRate: z.number().min(0.000001, 'Exchange rate must be greater than 0'), |
54 | | - isEnabled: z.boolean().default(true) |
| 7 | + parentId: z.string().optional() |
55 | 8 | }); |
56 | 9 |
|
57 | 10 | // Type exports for use in components |
58 | 11 | export type CategoryValidation = z.infer<typeof categorySchema>; |
59 | | -export type DiscountValidation = z.infer<typeof discountSchema>; |
60 | | -export type CurrencyValidation = z.infer<typeof currencySchema>; |
0 commit comments