|
| 1 | +import { oc } from "@orpc/contract"; |
| 2 | +import { z } from "zod"; |
| 3 | +import { CustomerSchema } from "../schemas/customer"; |
| 4 | +import { |
| 5 | + PaginationInputSchema, |
| 6 | + PaginationOutputSchema, |
| 7 | +} from "../schemas/pagination"; |
| 8 | + |
| 9 | +const ListCustomersInputSchema = PaginationInputSchema; |
| 10 | +const ListCustomersOutputSchema = PaginationOutputSchema.extend({ |
| 11 | + customers: z.array(CustomerSchema), |
| 12 | +}); |
| 13 | + |
| 14 | +const GetCustomerInputSchema = z.object({ id: z.string() }); |
| 15 | + |
| 16 | +const CreateCustomerInputSchema = z.object({ |
| 17 | + name: z.string().min(1), |
| 18 | + email: z.string().email(), |
| 19 | +}); |
| 20 | + |
| 21 | +const UpdateCustomerInputSchema = z.object({ |
| 22 | + id: z.string(), |
| 23 | + name: z.string().optional(), |
| 24 | + email: z.string().email().optional(), |
| 25 | + userMetadata: z.record(z.string(), z.string()).optional(), |
| 26 | +}); |
| 27 | + |
| 28 | +const DeleteCustomerInputSchema = z.object({ id: z.string() }); |
| 29 | + |
| 30 | +export const listCustomersContract = oc |
| 31 | + .input(ListCustomersInputSchema) |
| 32 | + .output(ListCustomersOutputSchema); |
| 33 | + |
| 34 | +export const getCustomerContract = oc |
| 35 | + .input(GetCustomerInputSchema) |
| 36 | + .output(CustomerSchema); |
| 37 | + |
| 38 | +export const createCustomerContract = oc |
| 39 | + .input(CreateCustomerInputSchema) |
| 40 | + .output(CustomerSchema); |
| 41 | + |
| 42 | +export const updateCustomerContract = oc |
| 43 | + .input(UpdateCustomerInputSchema) |
| 44 | + .output(CustomerSchema); |
| 45 | + |
| 46 | +export const deleteCustomerContract = oc |
| 47 | + .input(DeleteCustomerInputSchema) |
| 48 | + .output(z.object({ ok: z.literal(true) })); |
| 49 | + |
| 50 | +export const customer = { |
| 51 | + list: listCustomersContract, |
| 52 | + get: getCustomerContract, |
| 53 | + create: createCustomerContract, |
| 54 | + update: updateCustomerContract, |
| 55 | + delete: deleteCustomerContract, |
| 56 | +}; |
0 commit comments