94 lines
2.0 KiB
TypeScript
94 lines
2.0 KiB
TypeScript
import { IsOptional, IsString, IsNumber, Min, IsEnum, IsIn } 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: '张三',
|
|
})
|
|
@IsOptional()
|
|
@IsString()
|
|
realName?: 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;
|
|
|
|
@ApiPropertyOptional({
|
|
description: '排序字段',
|
|
example: 'createdAt',
|
|
default: 'createdAt',
|
|
})
|
|
@IsOptional()
|
|
@IsString()
|
|
@IsIn(['createdAt', 'updatedAt', 'lastLoginAt'])
|
|
sortBy?: string = 'createdAt';
|
|
|
|
@ApiPropertyOptional({
|
|
description: '排序方向',
|
|
example: 'DESC',
|
|
enum: ['ASC', 'DESC'],
|
|
default: 'DESC',
|
|
})
|
|
@IsOptional()
|
|
@IsString()
|
|
@IsIn(['ASC', 'DESC'])
|
|
sortOrder?: 'ASC' | 'DESC' = 'DESC';
|
|
}
|