forked from datawhale/whale-town-end
feat:实现完整的用户管理系统
- 添加Users实体定义,包含完整的字段映射和约束 - 实现CreateUserDto数据验证,支持所有字段验证规则 - 创建UsersService服务,提供完整的CRUD操作 - 添加UsersModule模块配置 - 支持用户搜索、统计、批量操作等高级功能
This commit is contained in:
59
src/core/db/users/users.dto.ts
Normal file
59
src/core/db/users/users.dto.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
// src/user/dto/create-user.dto.ts
|
||||
import {
|
||||
IsString,
|
||||
IsEmail,
|
||||
IsPhoneNumber,
|
||||
IsInt,
|
||||
Min,
|
||||
Max,
|
||||
IsOptional,
|
||||
Length,
|
||||
IsNotEmpty
|
||||
} from 'class-validator'
|
||||
|
||||
export class CreateUserDto {
|
||||
// 用户名:必填、字符串、长度1-50
|
||||
@IsString()
|
||||
@IsNotEmpty({ message: '用户名不能为空' })
|
||||
@Length(1, 50, { message: '用户名长度需在1-50字符之间' })
|
||||
username: string;
|
||||
|
||||
// 邮箱:可选、合法邮箱格式
|
||||
@IsOptional()
|
||||
@IsEmail({}, { message: '邮箱格式不正确' })
|
||||
email?: string;
|
||||
|
||||
// 手机号:可选、合法手机号格式(支持全球号码)
|
||||
@IsOptional()
|
||||
@IsPhoneNumber(null, { message: '手机号格式不正确' })
|
||||
phone?: string;
|
||||
|
||||
// 密码哈希:可选(OAuth登录为空)
|
||||
@IsOptional()
|
||||
@IsString({ message: '密码哈希必须是字符串' })
|
||||
password_hash?: string;
|
||||
|
||||
// 昵称:必填、字符串、长度1-50
|
||||
@IsString()
|
||||
@IsNotEmpty({ message: '昵称不能为空' })
|
||||
@Length(1, 50, { message: '昵称长度需在1-50字符之间' })
|
||||
nickname: string;
|
||||
|
||||
// GitHub ID:可选、字符串、长度1-100
|
||||
@IsOptional()
|
||||
@IsString({ message: 'GitHub ID必须是字符串' })
|
||||
@Length(1, 100, { message: 'GitHub ID长度需在1-100字符之间' })
|
||||
github_id?: string;
|
||||
|
||||
// 头像URL:可选、字符串
|
||||
@IsOptional()
|
||||
@IsString({ message: '头像URL必须是字符串' })
|
||||
avatar_url?: string;
|
||||
|
||||
// 角色:可选、数字、1(普通)或9(管理员)
|
||||
@IsOptional()
|
||||
@IsInt({ message: '角色必须是数字' })
|
||||
@Min(1, { message: '角色值最小为1' })
|
||||
@Max(9, { message: '角色值最大为9' })
|
||||
role?: number = 1; // 默认普通用户
|
||||
}
|
||||
Reference in New Issue
Block a user