city.schema.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { z } from '@hono/zod-openapi';
  2. export const CitySchema = z.object({
  3. id: z.number().int().positive().openapi({ description: '地区ID' }),
  4. name: z.string().min(1, '地区名称不能为空').max(255, '地区名称最多255个字符').openapi({
  5. description: '地区名称',
  6. example: '北京市'
  7. }),
  8. level: z.number().int().min(1).max(4).default(1).openapi({
  9. description: '层级 省市区县1,2,3,4',
  10. example: 1
  11. }),
  12. parentId: z.coerce.number<number>().int().nonnegative('上级ID必须为非负数').default(0).openapi({
  13. description: '上级地区ID',
  14. example: 0
  15. }),
  16. state: z.number().int().min(1).max(1).default(1).openapi({
  17. description: '状态 1可用',
  18. example: 1
  19. }),
  20. sort: z.number().int().nonnegative('排序值必须为非负数').default(0).openapi({
  21. description: '排序数值越大越靠前',
  22. example: 0
  23. }),
  24. createdAt: z.coerce.date().openapi({
  25. description: '创建时间',
  26. example: '2024-01-01T12:00:00Z'
  27. }),
  28. updatedAt: z.coerce.date().openapi({
  29. description: '更新时间',
  30. example: '2024-01-01T12:00:00Z'
  31. }),
  32. createdBy: z.number().int().positive().nullable().openapi({
  33. description: '创建用户ID',
  34. example: 1
  35. }),
  36. updatedBy: z.number().int().positive().nullable().openapi({
  37. description: '更新用户ID',
  38. example: 1
  39. })
  40. });
  41. export const CreateCityDto = z.object({
  42. name: z.string().min(1, '地区名称不能为空').max(255, '地区名称最多255个字符').openapi({
  43. description: '地区名称',
  44. example: '北京市'
  45. }),
  46. level: z.number().int().min(1, '层级必须在1-4之间').max(4, '层级必须在1-4之间').default(1).openapi({
  47. description: '层级 省市区县1,2,3,4',
  48. example: 1
  49. }),
  50. parentId: z.number().int().nonnegative('上级ID必须为非负数').default(0).openapi({
  51. description: '上级地区ID',
  52. example: 0
  53. }),
  54. state: z.number().int().min(1).max(1).default(1).openapi({
  55. description: '状态 1可用',
  56. example: 1
  57. }),
  58. sort: z.number().int().nonnegative('排序值必须为非负数').default(0).openapi({
  59. description: '排序数值越大越靠前',
  60. example: 0
  61. })
  62. });
  63. export const UpdateCityDto = z.object({
  64. name: z.string().min(1, '地区名称不能为空').max(255, '地区名称最多255个字符').optional().openapi({
  65. description: '地区名称',
  66. example: '北京市'
  67. }),
  68. level: z.number().int().min(1, '层级必须在1-4之间').max(4, '层级必须在1-4之间').optional().openapi({
  69. description: '层级 省市区县1,2,3,4',
  70. example: 1
  71. }),
  72. parentId: z.number().int().nonnegative('上级ID必须为非负数').optional().openapi({
  73. description: '上级地区ID',
  74. example: 0
  75. }),
  76. state: z.number().int().min(1).max(1).optional().openapi({
  77. description: '状态 1可用',
  78. example: 1
  79. }),
  80. sort: z.number().int().nonnegative('排序值必须为非负数').optional().openapi({
  81. description: '排序数值越大越靠前',
  82. example: 0
  83. })
  84. });