feat:初始化项目
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { IsString, IsNotEmpty, MinLength, MaxLength } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class ChangePasswordDto {
|
||||
@ApiProperty({
|
||||
description: '旧密码',
|
||||
example: 'OldPassword123!',
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
oldPassword: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: '新密码',
|
||||
example: 'NewPassword123!',
|
||||
minLength: 6,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MinLength(6)
|
||||
@MaxLength(100)
|
||||
newPassword: string;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import {
|
||||
IsString,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsEmail,
|
||||
MinLength,
|
||||
MaxLength,
|
||||
IsEnum,
|
||||
} from 'class-validator';
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { UserRole } from '../user.entity';
|
||||
|
||||
export class CreateUserDto {
|
||||
@ApiProperty({
|
||||
description: '用户名',
|
||||
example: 'admin',
|
||||
maxLength: 50,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MinLength(3)
|
||||
@MaxLength(50)
|
||||
username: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: '密码(明文,服务端会使用 bcrypt 加密后存储)',
|
||||
example: 'SecurePassword123!',
|
||||
minLength: 6,
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MinLength(6)
|
||||
@MaxLength(100)
|
||||
password: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '邮箱',
|
||||
example: 'admin@example.com',
|
||||
maxLength: 100,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
@MaxLength(100)
|
||||
email?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: '用户角色',
|
||||
enum: UserRole,
|
||||
example: UserRole.ADMIN,
|
||||
})
|
||||
@IsEnum(UserRole)
|
||||
@IsNotEmpty()
|
||||
role: UserRole;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '真实姓名',
|
||||
example: '张三',
|
||||
maxLength: 50,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
realName?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '头像URL',
|
||||
example: 'https://example.com/avatar.jpg',
|
||||
maxLength: 500,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(500)
|
||||
avatar?: string;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { User } from '../user.entity';
|
||||
|
||||
export class PaginationInfo {
|
||||
@ApiProperty({ description: '总记录数', example: 100 })
|
||||
total: number;
|
||||
|
||||
@ApiProperty({ description: '总页数', example: 10 })
|
||||
total_page: number;
|
||||
|
||||
@ApiProperty({ description: '每页数量', example: 10 })
|
||||
page_size: number;
|
||||
|
||||
@ApiProperty({ description: '当前页码', example: 1 })
|
||||
current_page: number;
|
||||
}
|
||||
|
||||
export class PaginatedUserData {
|
||||
@ApiProperty({ description: '用户列表', type: [User] })
|
||||
list: Omit<User, 'passwordHash'>[];
|
||||
|
||||
@ApiProperty({ description: '分页信息', type: PaginationInfo })
|
||||
pagination: PaginationInfo;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { IsOptional, IsString, IsNumber, Min, IsEnum } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { UserRole, UserStatus } from '../user.entity';
|
||||
|
||||
export class QueryUserDto {
|
||||
@ApiPropertyOptional({
|
||||
description: '用户名',
|
||||
example: 'admin',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
username?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '邮箱',
|
||||
example: 'admin@example.com',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '角色',
|
||||
enum: UserRole,
|
||||
example: UserRole.ADMIN,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(UserRole)
|
||||
role?: UserRole;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '状态',
|
||||
enum: UserStatus,
|
||||
example: UserStatus.ACTIVE,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(UserStatus)
|
||||
status?: UserStatus;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '页码',
|
||||
example: 1,
|
||||
minimum: 1,
|
||||
default: 1,
|
||||
})
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
page?: number = 1;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '每页数量',
|
||||
example: 10,
|
||||
minimum: 1,
|
||||
default: 10,
|
||||
})
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
limit?: number = 10;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { IsString, IsOptional, IsEmail, MaxLength, IsEnum } from 'class-validator';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { UserRole, UserStatus } from '../user.entity';
|
||||
|
||||
export class UpdateUserDto {
|
||||
@ApiPropertyOptional({
|
||||
description: '邮箱',
|
||||
example: 'newemail@example.com',
|
||||
maxLength: 100,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEmail()
|
||||
@MaxLength(100)
|
||||
email?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '真实姓名',
|
||||
example: '张三',
|
||||
maxLength: 50,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(50)
|
||||
realName?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '头像URL',
|
||||
example: 'https://example.com/avatar.jpg',
|
||||
maxLength: 500,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(500)
|
||||
avatar?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '用户状态',
|
||||
enum: UserStatus,
|
||||
example: UserStatus.ACTIVE,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(UserStatus)
|
||||
status?: UserStatus;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: '用户角色',
|
||||
enum: UserRole,
|
||||
example: UserRole.ADMIN,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsEnum(UserRole)
|
||||
role?: UserRole;
|
||||
}
|
||||
Reference in New Issue
Block a user