manicanldes-backend/src/addresses/address.schema.ts

25 lines
601 B
TypeScript

import { z } from 'zod';
import { text } from '../common/input';
export const addressSchema = z
.object({
recipient: text(160),
line1: text(200),
line2: text(200, 0).default(''),
city: text(100),
region: text(100),
postalCode: z
.string()
.trim()
.min(1)
.max(20)
.regex(/^[A-Za-z0-9 -]+$/),
countryCode: z
.string()
.toUpperCase()
.regex(/^[A-Z]{2}$/),
phone: z.string().regex(/^\+[1-9]\d{6,14}$/),
isDefault: z.boolean().default(false),
})
.strict();
export type AddressInput = z.infer<typeof addressSchema>;