goods-category.schema.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { z } from '@hono/zod-openapi';
  2. import { FileSchema } from '@/server/modules/files/file.schema';
  3. export const GoodsCategorySchema = z.object({
  4. id: z.number().int().positive().openapi({ description: '类别ID' }),
  5. name: z.string().min(1, '类别名称不能为空').max(255, '类别名称最多255个字符').openapi({
  6. description: '类别名称',
  7. example: '电子产品'
  8. }),
  9. parentId: z.number().int().nonnegative('上级ID必须为非负数').default(0).openapi({
  10. description: '上级分类ID',
  11. example: 0
  12. }),
  13. imageFileId: z.number().int().positive().nullable().openapi({
  14. description: '分类图片文件ID',
  15. example: 1
  16. }),
  17. level: z.number().int().nonnegative('层级必须为非负数').default(0).openapi({
  18. description: '分类层级',
  19. example: 1
  20. }),
  21. state: z.number().int().min(1).max(2).default(1).openapi({
  22. description: '状态 1可用 2不可用',
  23. example: 1
  24. }),
  25. imageFile: FileSchema.nullable().optional().openapi({
  26. description: '分类图片信息'
  27. }),
  28. createdAt: z.coerce.date().openapi({
  29. description: '创建时间',
  30. example: '2024-01-01T12:00:00Z'
  31. }),
  32. updatedAt: z.coerce.date().openapi({
  33. description: '更新时间',
  34. example: '2024-01-01T12:00:00Z'
  35. }),
  36. createdBy: z.number().int().positive().nullable().openapi({
  37. description: '创建用户ID',
  38. example: 1
  39. }),
  40. updatedBy: z.number().int().positive().nullable().openapi({
  41. description: '更新用户ID',
  42. example: 1
  43. })
  44. });
  45. export const CreateGoodsCategoryDto = z.object({
  46. name: z.string().min(1, '类别名称不能为空').max(255, '类别名称最多255个字符').openapi({
  47. description: '类别名称',
  48. example: '电子产品'
  49. }),
  50. parentId: z.number().int().nonnegative('上级ID必须为非负数').default(0).openapi({
  51. description: '上级分类ID',
  52. example: 0
  53. }),
  54. imageFileId: z.number().int().positive().nullable().optional().openapi({
  55. description: '分类图片文件ID',
  56. example: 1
  57. }),
  58. level: z.number().int().nonnegative('层级必须为非负数').default(0).openapi({
  59. description: '分类层级',
  60. example: 1
  61. }),
  62. state: z.number().int().min(1).max(2).default(1).openapi({
  63. description: '状态 1可用 2不可用',
  64. example: 1
  65. })
  66. });
  67. export const UpdateGoodsCategoryDto = z.object({
  68. name: z.string().min(1, '类别名称不能为空').max(255, '类别名称最多255个字符').optional().openapi({
  69. description: '类别名称',
  70. example: '电子产品'
  71. }),
  72. parentId: z.number().int().nonnegative('上级ID必须为非负数').optional().openapi({
  73. description: '上级分类ID',
  74. example: 0
  75. }),
  76. imageFileId: z.number().int().positive().nullable().optional().openapi({
  77. description: '分类图片文件ID',
  78. example: 1
  79. }),
  80. level: z.number().int().nonnegative('层级必须为非负数').optional().openapi({
  81. description: '分类层级',
  82. example: 1
  83. }),
  84. state: z.number().int().min(1).max(2).optional().openapi({
  85. description: '状态 1可用 2不可用',
  86. example: 1
  87. })
  88. });