| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import { z } from '@hono/zod-openapi';
- export const CitySchema = z.object({
- id: z.number().int().positive().openapi({ description: '地区ID' }),
- name: z.string().min(1, '地区名称不能为空').max(255, '地区名称最多255个字符').openapi({
- description: '地区名称',
- example: '北京市'
- }),
- level: z.number().int().min(1).max(4).default(1).openapi({
- description: '层级 省市区县1,2,3,4',
- example: 1
- }),
- parentId: z.coerce.number<number>().int().nonnegative('上级ID必须为非负数').default(0).openapi({
- description: '上级地区ID',
- example: 0
- }),
- state: z.number().int().min(1).max(1).default(1).openapi({
- description: '状态 1可用',
- example: 1
- }),
- sort: z.number().int().nonnegative('排序值必须为非负数').default(0).openapi({
- description: '排序数值越大越靠前',
- example: 0
- }),
- createdAt: z.coerce.date().openapi({
- description: '创建时间',
- example: '2024-01-01T12:00:00Z'
- }),
- updatedAt: z.coerce.date().openapi({
- description: '更新时间',
- example: '2024-01-01T12:00:00Z'
- }),
- createdBy: z.number().int().positive().nullable().openapi({
- description: '创建用户ID',
- example: 1
- }),
- updatedBy: z.number().int().positive().nullable().openapi({
- description: '更新用户ID',
- example: 1
- })
- });
- export const CreateCityDto = z.object({
- name: z.string().min(1, '地区名称不能为空').max(255, '地区名称最多255个字符').openapi({
- description: '地区名称',
- example: '北京市'
- }),
- level: z.number().int().min(1, '层级必须在1-4之间').max(4, '层级必须在1-4之间').default(1).openapi({
- description: '层级 省市区县1,2,3,4',
- example: 1
- }),
- parentId: z.number().int().nonnegative('上级ID必须为非负数').default(0).openapi({
- description: '上级地区ID',
- example: 0
- }),
- state: z.number().int().min(1).max(1).default(1).openapi({
- description: '状态 1可用',
- example: 1
- }),
- sort: z.number().int().nonnegative('排序值必须为非负数').default(0).openapi({
- description: '排序数值越大越靠前',
- example: 0
- })
- });
- export const UpdateCityDto = z.object({
- name: z.string().min(1, '地区名称不能为空').max(255, '地区名称最多255个字符').optional().openapi({
- description: '地区名称',
- example: '北京市'
- }),
- level: z.number().int().min(1, '层级必须在1-4之间').max(4, '层级必须在1-4之间').optional().openapi({
- description: '层级 省市区县1,2,3,4',
- example: 1
- }),
- parentId: z.number().int().nonnegative('上级ID必须为非负数').optional().openapi({
- description: '上级地区ID',
- example: 0
- }),
- state: z.number().int().min(1).max(1).optional().openapi({
- description: '状态 1可用',
- example: 1
- }),
- sort: z.number().int().nonnegative('排序值必须为非负数').optional().openapi({
- description: '排序数值越大越靠前',
- example: 0
- })
- });
|