|
|
@@ -2,6 +2,8 @@ import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable, CreateDa
|
|
|
import { Role, RoleSchema } from './role.entity';
|
|
|
import { z } from '@hono/zod-openapi';
|
|
|
import { DeleteStatus, DisabledStatus } from '@/share/types';
|
|
|
+import { UserType } from './user.enum';
|
|
|
+
|
|
|
|
|
|
@Entity({ name: 'users' })
|
|
|
export class UserEntity {
|
|
|
@@ -35,6 +37,15 @@ export class UserEntity {
|
|
|
@Column({ name: 'is_deleted', type: 'int', default: DeleteStatus.NOT_DELETED, comment: '是否删除(0:未删除,1:已删除)' })
|
|
|
isDeleted!: DeleteStatus;
|
|
|
|
|
|
+ @Column({
|
|
|
+ name: 'user_type',
|
|
|
+ type: 'enum',
|
|
|
+ enum: UserType,
|
|
|
+ default: UserType.STUDENT,
|
|
|
+ comment: '用户类型(teacher:老师,student:学生)'
|
|
|
+ })
|
|
|
+ userType!: UserType;
|
|
|
+
|
|
|
@ManyToMany(() => Role)
|
|
|
@JoinTable()
|
|
|
roles!: Role[];
|
|
|
@@ -94,6 +105,90 @@ export const UserSchema = z.object({
|
|
|
],
|
|
|
description: '用户角色列表'
|
|
|
}),
|
|
|
+ userType: z.enum([UserType.TEACHER, UserType.STUDENT]).default(UserType.STUDENT).openapi({
|
|
|
+ example: UserType.STUDENT,
|
|
|
+ description: '用户类型(teacher:老师,student:学生)'
|
|
|
+ }),
|
|
|
createdAt: z.date().openapi({ description: '创建时间' }),
|
|
|
updatedAt: z.date().openapi({ description: '更新时间' })
|
|
|
+});
|
|
|
+
|
|
|
+export const CreateUserDto = z.object({
|
|
|
+ username: z.string().min(3).max(255).openapi({
|
|
|
+ example: 'admin',
|
|
|
+ description: '用户名,3-255个字符'
|
|
|
+ }),
|
|
|
+ password: z.string().min(6).max(255).openapi({
|
|
|
+ example: 'password123',
|
|
|
+ description: '密码,最少6位'
|
|
|
+ }),
|
|
|
+ phone: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: '13800138000',
|
|
|
+ description: '手机号'
|
|
|
+ }),
|
|
|
+ email: z.string().email().max(255).nullable().optional().openapi({
|
|
|
+ example: 'user@example.com',
|
|
|
+ description: '邮箱'
|
|
|
+ }),
|
|
|
+ nickname: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: '昵称',
|
|
|
+ description: '用户昵称'
|
|
|
+ }),
|
|
|
+ name: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: '张三',
|
|
|
+ description: '真实姓名'
|
|
|
+ }),
|
|
|
+ avatar: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: 'https://example.com/avatar.jpg',
|
|
|
+ description: '用户头像'
|
|
|
+ }),
|
|
|
+ isDisabled: z.number().int().min(0).max(1).default(DisabledStatus.ENABLED).openapi({
|
|
|
+ example: DisabledStatus.ENABLED,
|
|
|
+ description: '是否禁用(0:启用,1:禁用)'
|
|
|
+ }),
|
|
|
+ userType: z.enum([UserType.TEACHER, UserType.STUDENT]).default(UserType.STUDENT).openapi({
|
|
|
+ example: UserType.STUDENT,
|
|
|
+ description: '用户类型(teacher:老师,student:学生)'
|
|
|
+ }),
|
|
|
+ createdAt: z.date().openapi({ description: '创建时间' }),
|
|
|
+ updatedAt: z.date().openapi({ description: '更新时间' })
|
|
|
+});
|
|
|
+
|
|
|
+export const UpdateUserDto = z.object({
|
|
|
+ username: z.string().min(3).max(255).optional().openapi({
|
|
|
+ example: 'admin',
|
|
|
+ description: '用户名,3-255个字符'
|
|
|
+ }),
|
|
|
+ password: z.string().min(6).max(255).optional().openapi({
|
|
|
+ example: 'password123',
|
|
|
+ description: '密码,最少6位'
|
|
|
+ }),
|
|
|
+ phone: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: '13800138000',
|
|
|
+ description: '手机号'
|
|
|
+ }),
|
|
|
+ email: z.string().email().max(255).nullable().optional().openapi({
|
|
|
+ example: 'user@example.com',
|
|
|
+ description: '邮箱'
|
|
|
+ }),
|
|
|
+ nickname: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: '昵称',
|
|
|
+ description: '用户昵称'
|
|
|
+ }),
|
|
|
+ name: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: '张三',
|
|
|
+ description: '真实姓名'
|
|
|
+ }),
|
|
|
+ avatar: z.string().max(255).nullable().optional().openapi({
|
|
|
+ example: 'https://example.com/avatar.jpg',
|
|
|
+ description: '用户头像'
|
|
|
+ }),
|
|
|
+ isDisabled: z.number().int().min(0).max(1).optional().openapi({
|
|
|
+ example: DisabledStatus.ENABLED,
|
|
|
+ description: '是否禁用(0:启用,1:禁用)'
|
|
|
+ }),
|
|
|
+ userType: z.enum([UserType.TEACHER, UserType.STUDENT]).optional().openapi({
|
|
|
+ example: UserType.STUDENT,
|
|
|
+ description: '用户类型(teacher:老师,student:学生)'
|
|
|
+ })
|
|
|
});
|