test-user.schema.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { z } from '@hono/zod-openapi';
  2. import { DeleteStatus, DisabledStatus } from '@d8d/shared-types';
  3. // 多租户基础用户 schema(测试版本,不包含tenantId验证)
  4. export const TestUserSchemaMt = z.object({
  5. id: z.number().int().positive().openapi({ description: '用户ID' }),
  6. tenantId: z.number().int().positive().openapi({ description: '租户ID' }),
  7. username: z.string().min(3, '用户名至少3个字符').max(255, '用户名最多255个字符').openapi({
  8. example: 'admin',
  9. description: '用户名,3-255个字符'
  10. }),
  11. password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
  12. example: 'password123',
  13. description: '密码,最少6位'
  14. }),
  15. phone: z.string().max(255, '手机号最多255个字符').nullable().openapi({
  16. example: '13800138000',
  17. description: '手机号'
  18. }),
  19. email: z.email('请输入正确的邮箱格式').max(255, '邮箱最多255个字符').nullable().openapi({
  20. example: 'user@example.com',
  21. description: '邮箱'
  22. }),
  23. nickname: z.string().max(255, '昵称最多255个字符').nullable().openapi({
  24. example: '昵称',
  25. description: '用户昵称'
  26. }),
  27. name: z.string().max(255, '姓名最多255个字符').nullable().openapi({
  28. example: '张三',
  29. description: '真实姓名'
  30. }),
  31. isDisabled: z.nativeEnum(DisabledStatus).default(DisabledStatus.ENABLED).openapi({
  32. example: DisabledStatus.ENABLED,
  33. description: '是否禁用(0:启用,1:禁用)'
  34. }),
  35. isDeleted: z.number().int().min(0).max(1).default(DeleteStatus.NOT_DELETED).openapi({
  36. example: DeleteStatus.NOT_DELETED,
  37. description: '是否删除(0:未删除,1:已删除)'
  38. }),
  39. openid: z.string().max(255).nullable().optional().openapi({
  40. example: 'oABCDEFGH123456789',
  41. description: '微信小程序openid'
  42. }),
  43. unionid: z.string().max(255).nullable().optional().openapi({
  44. example: 'unionid123456789',
  45. description: '微信unionid'
  46. }),
  47. registrationSource: z.string().max(20).default('web').openapi({
  48. example: 'miniapp',
  49. description: '注册来源: web, miniapp'
  50. }),
  51. createdAt: z.coerce.date().openapi({ description: '创建时间' }),
  52. updatedAt: z.coerce.date().openapi({ description: '更新时间' })
  53. });
  54. // 多租户创建用户请求 schema(测试版本)
  55. export const TestCreateUserDtoMt = z.object({
  56. username: z.string().min(3, '用户名至少3个字符').max(255, '用户名最多255个字符').openapi({
  57. example: 'admin',
  58. description: '用户名,3-255个字符'
  59. }),
  60. password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
  61. example: 'password123',
  62. description: '密码,最少6位'
  63. }),
  64. phone: z.string().max(255, '手机号最多255个字符').nullable().optional().openapi({
  65. example: '13800138000',
  66. description: '手机号'
  67. }),
  68. email: z.email('请输入正确的邮箱格式').max(255, '邮箱最多255个字符').nullable().optional().openapi({
  69. example: 'user@example.com',
  70. description: '邮箱'
  71. }),
  72. nickname: z.string().max(255, '昵称最多255个字符').nullable().optional().openapi({
  73. example: '昵称',
  74. description: '用户昵称'
  75. }),
  76. name: z.string().max(255, '姓名最多255个字符').nullable().optional().openapi({
  77. example: '张三',
  78. description: '真实姓名'
  79. }),
  80. isDisabled: z.number().int().min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').default(DisabledStatus.ENABLED).optional().openapi({
  81. example: DisabledStatus.ENABLED,
  82. description: '是否禁用(0:启用,1:禁用)'
  83. })
  84. });
  85. // 多租户更新用户请求 schema(测试版本)
  86. export const TestUpdateUserDtoMt = z.object({
  87. username: z.string().min(3, '用户名至少3个字符').max(255, '用户名最多255个字符').optional().openapi({
  88. example: 'admin',
  89. description: '用户名,3-255个字符'
  90. }),
  91. password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').optional().openapi({
  92. example: 'password123',
  93. description: '密码,最少6位'
  94. }),
  95. phone: z.string().max(255, '手机号最多255个字符').nullable().optional().openapi({
  96. example: '13800138000',
  97. description: '手机号'
  98. }),
  99. email: z.email('请输入正确的邮箱格式').max(255, '邮箱最多255个字符').nullable().optional().openapi({
  100. example: 'user@example.com',
  101. description: '邮箱'
  102. }),
  103. nickname: z.string().max(255, '昵称最多255个字符').nullable().optional().openapi({
  104. example: '昵称',
  105. description: '用户昵称'
  106. }),
  107. name: z.string().max(255, '姓名最多255个字符').nullable().optional().openapi({
  108. example: '张三',
  109. description: '真实姓名'
  110. }),
  111. isDisabled: z.number().int().min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').optional().openapi({
  112. example: DisabledStatus.ENABLED,
  113. description: '是否禁用(0:启用,1:禁用)'
  114. })
  115. });