|
1 | 1 | import { oc } from "@orpc/contract"; |
2 | 2 | import { z } from "zod"; |
3 | 3 | import { CurrencySchema } from "../schemas/currency"; |
| 4 | +import { ProductPriceInputSchema } from "../schemas/product-price-input"; |
4 | 5 |
|
5 | 6 | export const ProductPriceSchema = z.object({ |
6 | 7 | id: z.string(), |
@@ -31,6 +32,42 @@ export const listProductsContract = oc |
31 | 32 | .input(z.object({}).optional()) |
32 | 33 | .output(ListProductsOutputSchema); |
33 | 34 |
|
| 35 | +// CRUD input schemas |
| 36 | +const CreateProductInputSchema = z.object({ |
| 37 | + name: z.string().min(1), |
| 38 | + description: z.string().optional(), |
| 39 | + price: ProductPriceInputSchema, |
| 40 | + userMetadata: z.record(z.string(), z.string()).optional(), |
| 41 | +}); |
| 42 | + |
| 43 | +const UpdateProductInputSchema = z.object({ |
| 44 | + id: z.string(), |
| 45 | + name: z.string().min(1).optional(), |
| 46 | + description: z.string().optional(), |
| 47 | + price: ProductPriceInputSchema.optional(), |
| 48 | + userMetadata: z.record(z.string(), z.string()).optional(), |
| 49 | +}); |
| 50 | + |
| 51 | +export const getProductContract = oc |
| 52 | + .input(z.object({ id: z.string() })) |
| 53 | + .output(ProductSchema); |
| 54 | + |
| 55 | +export const createProductContract = oc |
| 56 | + .input(CreateProductInputSchema) |
| 57 | + .output(ProductSchema); |
| 58 | + |
| 59 | +export const updateProductContract = oc |
| 60 | + .input(UpdateProductInputSchema) |
| 61 | + .output(ProductSchema); |
| 62 | + |
| 63 | +export const deleteProductContract = oc |
| 64 | + .input(z.object({ id: z.string() })) |
| 65 | + .output(z.object({ ok: z.literal(true) })); |
| 66 | + |
34 | 67 | export const products = { |
35 | 68 | list: listProductsContract, |
| 69 | + get: getProductContract, |
| 70 | + create: createProductContract, |
| 71 | + update: updateProductContract, |
| 72 | + delete: deleteProductContract, |
36 | 73 | }; |
0 commit comments