user-supplier.schema.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { z } from '@hono/zod-openapi';
  2. export const UserSupplierSchema = z.object({
  3. id: z.number().int().positive().openapi({ description: '供应商ID' }),
  4. name: z.string().min(1, '供货商名称不能为空').max(255, '供货商名称最多255个字符').nullable().openapi({
  5. description: '供货商名称',
  6. example: '供应商A'
  7. }),
  8. username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
  9. description: '用户名',
  10. example: 'supplier001'
  11. }),
  12. phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
  13. description: '手机号码',
  14. example: '13800138000'
  15. }),
  16. realname: z.string().max(20, '姓名最多20个字符').nullable().optional().openapi({
  17. description: '姓名',
  18. example: '张三'
  19. }),
  20. loginNum: z.number().int().nonnegative('登录次数必须为非负数').default(0).openapi({
  21. description: '登录次数',
  22. example: 0
  23. }),
  24. loginTime: z.number().int().nonnegative('登录时间必须为非负数').default(0).openapi({
  25. description: '登录时间',
  26. example: 0
  27. }),
  28. loginIp: z.string().max(15, 'IP地址最多15个字符').nullable().optional().openapi({
  29. description: '登录IP',
  30. example: '192.168.1.1'
  31. }),
  32. lastLoginTime: z.number().int().nonnegative('上次登录时间必须为非负数').default(0).openapi({
  33. description: '上次登录时间',
  34. example: 0
  35. }),
  36. lastLoginIp: z.string().max(15, 'IP地址最多15个字符').nullable().optional().openapi({
  37. description: '上次登录IP',
  38. example: '192.168.1.1'
  39. }),
  40. state: z.number().int().min(1).max(2).default(2).openapi({
  41. description: '状态 1启用 2禁用',
  42. example: 1
  43. }),
  44. createdAt: z.coerce.date().openapi({
  45. description: '创建时间',
  46. example: '2024-01-01T12:00:00Z'
  47. }),
  48. updatedAt: z.coerce.date().openapi({
  49. description: '更新时间',
  50. example: '2024-01-01T12:00:00Z'
  51. })
  52. });
  53. export const CreateUserSupplierDto = z.object({
  54. name: z.string().min(1, '供货商名称不能为空').max(255, '供货商名称最多255个字符').nullable().optional().openapi({
  55. description: '供货商名称',
  56. example: '供应商A'
  57. }),
  58. username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').openapi({
  59. description: '用户名',
  60. example: 'supplier001'
  61. }),
  62. password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
  63. description: '密码',
  64. example: 'password123'
  65. }),
  66. phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
  67. description: '手机号码',
  68. example: '13800138000'
  69. }),
  70. realname: z.string().max(20, '姓名最多20个字符').nullable().optional().openapi({
  71. description: '姓名',
  72. example: '张三'
  73. }),
  74. state: z.number().int().min(1).max(2).default(2).openapi({
  75. description: '状态 1启用 2禁用',
  76. example: 1
  77. })
  78. });
  79. export const UpdateUserSupplierDto = z.object({
  80. name: z.string().min(1, '供货商名称不能为空').max(255, '供货商名称最多255个字符').nullable().optional().openapi({
  81. description: '供货商名称',
  82. example: '供应商A'
  83. }),
  84. username: z.string().min(1, '用户名不能为空').max(20, '用户名最多20个字符').optional().openapi({
  85. description: '用户名',
  86. example: 'supplier001'
  87. }),
  88. password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').optional().openapi({
  89. description: '密码',
  90. example: 'password123'
  91. }),
  92. phone: z.string().regex(/^1[3-9]\d{9}$/, '请输入正确的手机号').nullable().optional().openapi({
  93. description: '手机号码',
  94. example: '13800138000'
  95. }),
  96. realname: z.string().max(20, '姓名最多20个字符').nullable().optional().openapi({
  97. description: '姓名',
  98. example: '张三'
  99. }),
  100. state: z.number().int().min(1).max(2).optional().openapi({
  101. description: '状态 1启用 2禁用',
  102. example: 1
  103. })
  104. });