feat: 优化项目目录结构
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class CreatePermissionDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
description: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { ArrayMinSize, IsArray, IsUUID } from 'class-validator';
|
||||
|
||||
export class DeleteRolePermissionsDto {
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@IsUUID('4', { each: true })
|
||||
permissionIds: string[];
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { ArrayMinSize, IsArray, IsUUID } from 'class-validator';
|
||||
|
||||
export class SetRolePermissionsDto {
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@IsUUID('4', { each: true })
|
||||
permissionIds: string[];
|
||||
}
|
||||
9
apps/backend/src/admin/dto/admin-role/create-role.dto.ts
Normal file
9
apps/backend/src/admin/dto/admin-role/create-role.dto.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class CreateRoleDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
localName: string;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { IsBoolean, IsDateString, IsOptional, IsUUID } from 'class-validator';
|
||||
|
||||
export class CreateUserRoleDto {
|
||||
@IsUUID('4')
|
||||
roleId: string;
|
||||
|
||||
@IsBoolean()
|
||||
isEnabled: boolean;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
expiredAt?: Date;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IsUUID } from 'class-validator';
|
||||
|
||||
export class DeleteUserRoleDto {
|
||||
@IsUUID('4')
|
||||
roleId: string;
|
||||
}
|
||||
32
apps/backend/src/admin/dto/admin-user/create.dto.ts
Normal file
32
apps/backend/src/admin/dto/admin-user/create.dto.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { IsString, Length, Matches, ValidateIf } from 'class-validator';
|
||||
|
||||
export class CreateDto {
|
||||
@ValidateIf((o) => o.username !== null)
|
||||
@IsString({ message: '用户名不得为空' })
|
||||
@Length(4, 32, { message: '用户名长度只能为4~32' })
|
||||
username: string | null;
|
||||
|
||||
@ValidateIf((o) => o.nickname !== null)
|
||||
@IsString({ message: '昵称不得为空' })
|
||||
@Length(1, 30, { message: '昵称长度只能为1~30' })
|
||||
nickname: string | null;
|
||||
|
||||
@ValidateIf((o) => o.email !== null)
|
||||
@IsString({ message: '邮箱不得为空' })
|
||||
@Length(6, 254, { message: '邮箱长度只能为6~254' })
|
||||
email: string | null;
|
||||
|
||||
@ValidateIf((o) => o.phone !== null)
|
||||
@IsString({ message: '手机号不得为空' })
|
||||
@Length(11, 11, { message: '手机号长度只能为11' })
|
||||
phone: string | null;
|
||||
|
||||
@ValidateIf((o) => o.password !== null)
|
||||
@IsString({ message: '密码不得为空' })
|
||||
@Length(6, 32, { message: '密码长度只能为6~32' })
|
||||
@Matches(
|
||||
/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/,
|
||||
{ message: '密码必须包含字母和数字,且长度在6~32之间' },
|
||||
)
|
||||
password: string | null;
|
||||
}
|
||||
3
apps/backend/src/admin/dto/admin-user/list.dto.ts
Normal file
3
apps/backend/src/admin/dto/admin-user/list.dto.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { PaginationDto } from '../common/pagination.dto';
|
||||
|
||||
export class ListDto extends PaginationDto {}
|
||||
8
apps/backend/src/admin/dto/admin-user/remove.dto.ts
Normal file
8
apps/backend/src/admin/dto/admin-user/remove.dto.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsBoolean } from 'class-validator';
|
||||
|
||||
export class RemoveUserDto {
|
||||
@Transform(({ value }) => value === 'true')
|
||||
@IsBoolean({ message: '需指定删除类型' })
|
||||
soft: boolean;
|
||||
}
|
||||
11
apps/backend/src/admin/dto/admin-user/update-password.dto.ts
Normal file
11
apps/backend/src/admin/dto/admin-user/update-password.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { IsString, Length, Matches } from 'class-validator';
|
||||
|
||||
export class UpdatePasswordDto {
|
||||
@IsString({ message: '密码不得为空' })
|
||||
@Length(6, 32, { message: '密码长度只能为6~32' })
|
||||
@Matches(
|
||||
/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/,
|
||||
{ message: '密码必须包含字母和数字,且长度在6~32之间' },
|
||||
)
|
||||
password: string;
|
||||
}
|
||||
35
apps/backend/src/admin/dto/admin-user/update.dto.ts
Normal file
35
apps/backend/src/admin/dto/admin-user/update.dto.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
IsEmail,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Length,
|
||||
Matches,
|
||||
} from 'class-validator';
|
||||
|
||||
export class UpdateDto {
|
||||
@IsString({ message: '用户名不得为空' })
|
||||
@Length(4, 32, { message: '用户名长度只能为4~32' })
|
||||
username: string;
|
||||
|
||||
@IsString({ message: '昵称不得为空' })
|
||||
@Length(1, 30, { message: '昵称长度只能为1~30' })
|
||||
nickname: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsEmail({}, { message: '请输入有效的邮箱地址', always: false })
|
||||
@Length(6, 254, {
|
||||
message: '邮箱长度只能为6~254',
|
||||
// 仅在值不为 null 或 undefined 时验证
|
||||
always: false,
|
||||
})
|
||||
email?: string;
|
||||
|
||||
@IsOptional() // 标记字段为可选
|
||||
@IsString({ message: '手机号不得为空', always: false })
|
||||
@Matches(/^1[3456789]\d{9}$/, {
|
||||
message: '请输入有效的手机号码',
|
||||
// 仅在值不为 null 或 undefined 时验证
|
||||
always: false,
|
||||
})
|
||||
phone?: string;
|
||||
}
|
||||
19
apps/backend/src/admin/dto/admin-web/create-blog.dto.ts
Normal file
19
apps/backend/src/admin/dto/admin-web/create-blog.dto.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { IsEnum, IsString } from 'class-validator';
|
||||
import { BlogPermission } from 'src/blog/blog.permission.enum';
|
||||
|
||||
export class CreateBlogDto {
|
||||
@IsString()
|
||||
title: string;
|
||||
|
||||
@IsString()
|
||||
description: string;
|
||||
|
||||
@IsString()
|
||||
contentUrl: string;
|
||||
|
||||
@IsEnum(BlogPermission, { each: true, message: '请求类型错误' })
|
||||
permissions: BlogPermission[];
|
||||
|
||||
@IsString()
|
||||
password: string; // 允许空串
|
||||
}
|
||||
28
apps/backend/src/admin/dto/admin-web/create-resource.dto.ts
Normal file
28
apps/backend/src/admin/dto/admin-web/create-resource.dto.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsString, ValidateNested } from 'class-validator';
|
||||
|
||||
class ResourceTagDto {
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
type: string;
|
||||
}
|
||||
|
||||
export class CreateResourceDto {
|
||||
@IsString()
|
||||
title: string;
|
||||
|
||||
@IsString()
|
||||
description: string;
|
||||
|
||||
@IsString()
|
||||
imageUrl: string;
|
||||
|
||||
@IsString()
|
||||
link: string;
|
||||
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => ResourceTagDto)
|
||||
tags: ResourceTagDto[];
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class SetBlogPasswordDto {
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
16
apps/backend/src/admin/dto/admin-web/update-blog.dto.ts
Normal file
16
apps/backend/src/admin/dto/admin-web/update-blog.dto.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { IsEnum, IsString } from 'class-validator';
|
||||
import { BlogPermission } from 'src/blog/blog.permission.enum';
|
||||
|
||||
export class UpdateBlogDto {
|
||||
@IsString()
|
||||
title: string;
|
||||
|
||||
@IsString()
|
||||
description: string;
|
||||
|
||||
@IsString()
|
||||
contentUrl: string;
|
||||
|
||||
@IsEnum(BlogPermission, { each: true, message: '请求类型错误' })
|
||||
permissions: BlogPermission[];
|
||||
}
|
||||
16
apps/backend/src/admin/dto/common/pagination.dto.ts
Normal file
16
apps/backend/src/admin/dto/common/pagination.dto.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsInt, IsOptional, Min } from 'class-validator';
|
||||
|
||||
export class PaginationDto {
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
page?: number = 1;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@Min(1)
|
||||
pageSize?: number = 20;
|
||||
}
|
||||
Reference in New Issue
Block a user