|
| 1 | +// src/validations/product.validation.ts |
| 2 | +import { z } from "zod"; |
| 3 | + |
| 4 | +export const createProductSchema = z.object({ |
| 5 | + body: z.object({ |
| 6 | + name: z.string().min(1, "Name is required"), |
| 7 | + description: z.string().min(1, "Description is required"), |
| 8 | + price: z.number().positive(), |
| 9 | + category: z.string().optional(), |
| 10 | + stock: z.number().optional(), |
| 11 | + }), |
| 12 | +}); |
| 13 | + |
| 14 | +export const updateProductSchema = z.object({ |
| 15 | + params: z.object({ |
| 16 | + id: z.string(), |
| 17 | + }), |
| 18 | + body: z.object({ |
| 19 | + name: z.string().optional(), |
| 20 | + description: z.string().optional(), |
| 21 | + price: z.number().optional(), |
| 22 | + category: z.string().optional(), |
| 23 | + stock: z.number().optional(), |
| 24 | + }), |
| 25 | +}); |
| 26 | + |
| 27 | +export const getProductByIdSchema = z.object({ |
| 28 | + params: z.object({ |
| 29 | + id: z.string(), |
| 30 | + }), |
| 31 | +}); |
| 32 | + |
| 33 | +export const deleteProductSchema = z.object({ |
| 34 | + params: z.object({ |
| 35 | + id: z.string(), |
| 36 | + }), |
| 37 | +}); |
| 38 | + |
| 39 | +export const getProductsSchema = z.object({ |
| 40 | + query: z.object({ |
| 41 | + search: z.string().optional(), |
| 42 | + category: z.string().optional(), |
| 43 | + minPrice: z.string().optional(), |
| 44 | + maxPrice: z.string().optional(), |
| 45 | + sort: z.enum(["asc", "desc", "lowToHigh", "highToLow"]).optional(), |
| 46 | + }), |
| 47 | +}); |
0 commit comments