| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- import { z } from '@hono/zod-openapi';
- import { DeleteStatus, DisabledStatus, UserType } from '@d8d/shared-types';
- import { RoleSchemaMt } from './role.schema';
- import { CompanySchema } from '@d8d/allin-company-module/schemas';
- // 多租户基础用户 schema(包含所有字段)
- export const UserSchemaMt = z.object({
- id: z.number().int().positive().openapi({ description: '用户ID' }),
- tenantId: z.number().int().positive().openapi({ description: '租户ID' }),
- username: z.string().min(3, '用户名至少3个字符').max(255, '用户名最多255个字符').openapi({
- example: 'admin',
- description: '用户名,3-255个字符'
- }),
- password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
- example: 'password123',
- description: '密码,最少6位'
- }),
- phone: z.string().max(255, '手机号最多255个字符').nullable().openapi({
- example: '13800138000',
- description: '手机号'
- }),
- email: z.email('请输入正确的邮箱格式').max(255, '邮箱最多255个字符').nullable().openapi({
- example: 'user@example.com',
- description: '邮箱'
- }),
- nickname: z.string().max(255, '昵称最多255个字符').nullable().openapi({
- example: '昵称',
- description: '用户昵称'
- }),
- name: z.string().max(255, '姓名最多255个字符').nullable().openapi({
- example: '张三',
- description: '真实姓名'
- }),
- avatarFileId: z.number().int().positive().nullable().openapi({
- example: 1,
- description: '头像文件ID'
- }),
- userType: z.nativeEnum(UserType).default(UserType.ADMIN).openapi({
- example: UserType.ADMIN,
- description: '用户类型: admin(管理员), employer(企业用户), talent(人才用户)'
- }),
- avatarFile: z.object({
- id: z.number().int().positive().openapi({ description: '文件ID' }),
- name: z.string().max(255).openapi({ description: '文件名', example: 'avatar.jpg' }),
- fullUrl: z.string().openapi({ description: '文件完整URL', example: 'https://example.com/avatar.jpg' }),
- type: z.string().nullable().openapi({ description: '文件类型', example: 'image/jpeg' }),
- size: z.number().nullable().openapi({ description: '文件大小(字节)', example: 102400 })
- }).nullable().optional().openapi({
- description: '头像文件信息'
- }),
- companyId: z.number().int().positive().nullable().openapi({
- example: 1,
- description: '公司ID,引用employer_company.company_id'
- }),
- company: CompanySchema.nullable().optional().openapi({
- description: '关联的公司信息'
- }),
- personId: z.number().int().positive().nullable().openapi({
- example: 1,
- description: '残疾人ID,引用disabled_person.person_id'
- }),
- person: z.object({
- id: z.number().int().positive().openapi({ description: '残疾人ID' }),
- name: z.string().openapi({ description: '姓名' }),
- disabilityId: z.string().openapi({ description: '残疾证号' })
- }).nullable().optional().openapi({
- description: '关联的残疾人信息'
- }),
- openid: z.string().max(255).nullable().optional().openapi({
- example: 'oABCDEFGH123456789',
- description: '微信小程序openid'
- }),
- unionid: z.string().max(255).nullable().optional().openapi({
- example: 'unionid123456789',
- description: '微信unionid'
- }),
- registrationSource: z.string().max(20).default('web').openapi({
- example: 'miniapp',
- description: '注册来源: web, miniapp'
- }),
- isDisabled: z.nativeEnum(DisabledStatus).default(DisabledStatus.ENABLED).openapi({
- example: DisabledStatus.ENABLED,
- description: '是否禁用(0:启用,1:禁用)'
- }),
- isDeleted: z.number().int().min(0).max(1).default(DeleteStatus.NOT_DELETED).openapi({
- example: DeleteStatus.NOT_DELETED,
- description: '是否删除(0:未删除,1:已删除)'
- }),
- roles: z.array(RoleSchemaMt).optional().openapi({
- example: [
- {
- id: 1,
-
- name: 'admin',
- description: '管理员',
- permissions: ['user:create'],
- createdAt: new Date(),
- updatedAt: new Date()
- }
- ],
- description: '用户角色列表'
- }),
- createdAt: z.coerce.date().openapi({ description: '创建时间' }),
- updatedAt: z.coerce.date().openapi({ description: '更新时间' })
- });
- // 多租户创建用户请求 schema
- export const CreateUserDtoMt = z.object({
- username: z.string().min(3, '用户名至少3个字符').max(255, '用户名最多255个字符').openapi({
- example: 'admin',
- description: '用户名,3-255个字符'
- }),
- password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').openapi({
- example: 'password123',
- description: '密码,最少6位'
- }),
- phone: z.string().max(255, '手机号最多255个字符').nullable().optional().openapi({
- example: '13800138000',
- description: '手机号'
- }),
- email: z.email('请输入正确的邮箱格式').max(255, '邮箱最多255个字符').nullable().optional().openapi({
- example: 'user@example.com',
- description: '邮箱'
- }),
- nickname: z.string().max(255, '昵称最多255个字符').nullable().optional().openapi({
- example: '昵称',
- description: '用户昵称'
- }),
- name: z.string().max(255, '姓名最多255个字符').nullable().optional().openapi({
- example: '张三',
- description: '真实姓名'
- }),
- avatarFileId: z.number().int().positive().nullable().optional().openapi({
- example: 1,
- description: '头像文件ID'
- }),
- userType: z.nativeEnum(UserType).default(UserType.ADMIN).optional().openapi({
- example: UserType.ADMIN,
- description: '用户类型: admin(管理员), employer(企业用户), talent(人才用户)'
- }),
- companyId: z.number().int().positive().nullable().optional().openapi({
- example: 1,
- description: '公司ID,引用employer_company.company_id'
- }),
- personId: z.number().int().positive().nullable().optional().openapi({
- example: 1,
- description: '残疾人ID,引用disabled_person.person_id'
- }),
- isDisabled: z.number().int().min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').default(DisabledStatus.ENABLED).optional().openapi({
- example: DisabledStatus.ENABLED,
- description: '是否禁用(0:启用,1:禁用)'
- })
- });
- // 多租户更新用户请求 schema
- export const UpdateUserDtoMt = z.object({
- username: z.string().min(3, '用户名至少3个字符').max(255, '用户名最多255个字符').optional().openapi({
- example: 'admin',
- description: '用户名,3-255个字符'
- }),
- password: z.string().min(6, '密码至少6位').max(255, '密码最多255位').optional().openapi({
- example: 'password123',
- description: '密码,最少6位'
- }),
- phone: z.string().max(255, '手机号最多255个字符').nullable().optional().openapi({
- example: '13800138000',
- description: '手机号'
- }),
- email: z.email('请输入正确的邮箱格式').max(255, '邮箱最多255个字符').nullable().optional().openapi({
- example: 'user@example.com',
- description: '邮箱'
- }),
- nickname: z.string().max(255, '昵称最多255个字符').nullable().optional().openapi({
- example: '昵称',
- description: '用户昵称'
- }),
- name: z.string().max(255, '姓名最多255个字符').nullable().optional().openapi({
- example: '张三',
- description: '真实姓名'
- }),
- avatarFileId: z.number().int().positive().nullable().optional().openapi({
- example: 1,
- description: '头像文件ID'
- }),
- userType: z.nativeEnum(UserType).optional().openapi({
- example: UserType.ADMIN,
- description: '用户类型: admin(管理员), employer(企业用户), talent(人才用户)'
- }),
- companyId: z.number().int().positive().nullable().optional().openapi({
- example: 1,
- description: '公司ID,引用employer_company.company_id'
- }),
- personId: z.number().int().positive().nullable().optional().openapi({
- example: 1,
- description: '残疾人ID,引用disabled_person.person_id'
- }),
- isDisabled: z.number().int().min(0, '状态值只能是0或1').max(1, '状态值只能是0或1').optional().openapi({
- example: DisabledStatus.ENABLED,
- description: '是否禁用(0:启用,1:禁用)'
- })
- });
- // 多租户用户列表响应 schema
- export const UserListResponseMt = z.object({
- data: z.array(UserSchemaMt.omit({ password: true })),
- pagination: z.object({
- total: z.number().openapi({
- example: 100,
- description: '总记录数'
- }),
- current: z.number().openapi({
- example: 1,
- description: '当前页码'
- }),
- pageSize: z.number().openapi({
- example: 10,
- description: '每页数量'
- })
- })
- });
- // 多租户单个用户查询响应 schema
- export const UserResponseSchemaMt = UserSchemaMt.omit({password:true})
- // 非多租户基础用户 schema(不包含tenantId字段)
- export const UserSchema = UserSchemaMt.omit({ tenantId: true })
- // 非多租户创建用户请求 schema
- export const CreateUserDto = CreateUserDtoMt
- // 非多租户更新用户请求 schema
- export const UpdateUserDto = UpdateUserDtoMt
- // 非多租户用户列表响应 schema
- export const UserListResponse = UserListResponseMt
- // 非多租户单个用户查询响应 schema
- export const UserResponseSchema = UserSchema.omit({password:true})
- // 非多租户类型导出
- export type User = z.infer<typeof UserSchema>;
- export type CreateUserRequest = z.infer<typeof CreateUserDto>;
- export type UpdateUserRequest = z.infer<typeof UpdateUserDto>;
- export type UserListResponseType = z.infer<typeof UserListResponse>;
- // 多租户类型导出
- export type UserMt = z.infer<typeof UserSchemaMt>;
- export type CreateUserRequestMt = z.infer<typeof CreateUserDtoMt>;
- export type UpdateUserRequestMt = z.infer<typeof UpdateUserDtoMt>;
- export type UserListResponseTypeMt = z.infer<typeof UserListResponseMt>;
|