format + lint

This commit is contained in:
2025-06-14 14:12:18 +08:00
parent e777afc433
commit 90a67b681e
69 changed files with 1756 additions and 1583 deletions

View File

@@ -16,9 +16,7 @@ import { BlogModule } from 'src/blog/blog.module';
@Module({
imports: [
TypeOrmModule.forFeature([
User,
]),
TypeOrmModule.forFeature([User]),
UserModule,
RoleModule,
ResourceModule,
@@ -35,4 +33,4 @@ import { BlogModule } from 'src/blog/blog.module';
AdminWebBlogController,
],
})
export class AdminModule { }
export class AdminModule {}

View File

@@ -1,31 +1,31 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post } from "@nestjs/common";
import { PermissionService } from "src/role/services/permission.service";
import { CreatePermissionDto } from "../dto/admin-permission/create-permission.dto";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
} from '@nestjs/common';
import { PermissionService } from 'src/role/services/permission.service';
import { CreatePermissionDto } from '../dto/admin-permission/create-permission.dto';
@Controller('admin/permission')
export class AdminPermissionController {
constructor(private readonly permissionService: PermissionService) {}
constructor(
private readonly permissionService: PermissionService,
) { }
@Get()
async list() {
return this.permissionService.list();
}
@Get()
async list() {
return this.permissionService.list();
}
@Post()
async create(@Body() dto: CreatePermissionDto) {
return this.permissionService.create(dto);
}
@Post()
async create(
@Body() dto: CreatePermissionDto
) {
return this.permissionService.create(dto);
}
@Delete(':id')
async delete(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
) {
return this.permissionService.delete(id);
}
}
@Delete(':id')
async delete(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.permissionService.delete(id);
}
}

View File

@@ -1,37 +1,51 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post } from "@nestjs/common";
import { PermissionService } from "src/role/services/permission.service";
import { RolePermissionService } from "src/role/services/role-permission.service";
import { SetRolePermissionsDto } from "../dto/admin-role-permission/set-role-permissions.dto";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
} from '@nestjs/common';
import { PermissionService } from 'src/role/services/permission.service';
import { RolePermissionService } from 'src/role/services/role-permission.service';
import { SetRolePermissionsDto } from '../dto/admin-role-permission/set-role-permissions.dto';
@Controller('admin/roles/:roleId/permission')
export class AdminRolePermissionController {
constructor(
private readonly rolePermissionService: RolePermissionService,
private readonly permissionService: PermissionService,
) {}
constructor(
private readonly rolePermissionService: RolePermissionService,
private readonly permissionService: PermissionService,
) { }
@Get()
async getRolePermissions(
@Param('roleId', new ParseUUIDPipe({ version: '4' })) roleId: string,
) {
const permissionIds =
await this.rolePermissionService.findPermissionIdsByRoleIds([roleId]);
return await this.permissionService.findPermissionByIds(permissionIds);
}
@Get()
async getRolePermissions(
@Param('roleId', new ParseUUIDPipe({ version: '4' })) roleId: string,
) {
const permissionIds = await this.rolePermissionService.findPermissionIdsByRoleIds([roleId]);
return await this.permissionService.findPermissionByIds(permissionIds);
}
@Post()
async setRolePermissions(
@Param('roleId', new ParseUUIDPipe({ version: '4' })) roleId: string,
@Body() dto: SetRolePermissionsDto,
) {
return await this.rolePermissionService.addRolePermissions(
roleId,
dto.permissionIds,
);
}
@Post()
async setRolePermissions(
@Param('roleId', new ParseUUIDPipe({ version: '4' })) roleId: string,
@Body() dto: SetRolePermissionsDto,
) {
return await this.rolePermissionService.addRolePermissions(roleId, dto.permissionIds);
}
@Delete()
async DeleteRolePermissionsDto(
@Param('roleId', new ParseUUIDPipe({ version: '4' })) roleId: string,
@Body() dto: SetRolePermissionsDto,
) {
return await this.rolePermissionService.deleteRolePermissions(roleId, dto.permissionIds);
}
}
@Delete()
async DeleteRolePermissionsDto(
@Param('roleId', new ParseUUIDPipe({ version: '4' })) roleId: string,
@Body() dto: SetRolePermissionsDto,
) {
return await this.rolePermissionService.deleteRolePermissions(
roleId,
dto.permissionIds,
);
}
}

View File

@@ -1,30 +1,31 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post } from "@nestjs/common";
import { RoleService } from "src/role/services/role.service";
import { CreateRoleDto } from "../dto/admin-role/create-role.dto";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
} from '@nestjs/common';
import { RoleService } from 'src/role/services/role.service';
import { CreateRoleDto } from '../dto/admin-role/create-role.dto';
@Controller('admin/role')
export class AdminRoleController {
constructor(private readonly roleService: RoleService) {}
constructor(
private readonly roleService: RoleService,
) { }
@Get()
async list() {
return this.roleService.list();
}
@Get()
async list() {
return this.roleService.list();
}
@Post()
async create(@Body() dto: CreateRoleDto) {
return this.roleService.create(dto);
}
@Post()
async create(
@Body() dto: CreateRoleDto
) {
return this.roleService.create(dto);
}
@Delete(':id')
async delete(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
) {
return this.roleService.delete(id);
}
}
@Delete(':id')
async delete(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.roleService.delete(id);
}
}

View File

@@ -1,43 +1,50 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post } from "@nestjs/common";
import { RoleService } from "src/role/services/role.service";
import { UserRoleService } from "src/role/services/user-role.service";
import { CreateUserRoleDto } from "../dto/admin-user-role/create-user-role.dto";
import { DeleteUserRoleDto } from "../dto/admin-user-role/delete-user-role.dto";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
} from '@nestjs/common';
import { RoleService } from 'src/role/services/role.service';
import { UserRoleService } from 'src/role/services/user-role.service';
import { CreateUserRoleDto } from '../dto/admin-user-role/create-user-role.dto';
import { DeleteUserRoleDto } from '../dto/admin-user-role/delete-user-role.dto';
@Controller('admin/users/:userId/role')
export class AdminUserRoleController {
constructor(
private readonly userRoleService: UserRoleService,
private readonly roleService: RoleService,
) {}
constructor(
private readonly userRoleService: UserRoleService,
private readonly roleService: RoleService,
) { }
@Get()
async getUserRoles(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
) {
const userRoleIds = await this.userRoleService.findRoleIdsByUserId(userId);
return await this.roleService.findRolesByRoleIds(userRoleIds);
}
@Get()
async getUserRoles(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
) {
const userRoleIds = await this.userRoleService.findRoleIdsByUserId(userId);
return await this.roleService.findRolesByRoleIds(userRoleIds);
}
@Post()
async setUserRoles(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() dto: CreateUserRoleDto,
) {
return this.userRoleService.addUserRole({
userId,
roleId: dto.roleId,
isEnabled: dto.isEnabled,
expiredAt: dto.expiredAt,
});
}
@Post()
async setUserRoles(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() dto: CreateUserRoleDto,
) {
return this.userRoleService.addUserRole({
userId,
roleId: dto.roleId,
isEnabled: dto.isEnabled,
expiredAt: dto.expiredAt,
});
}
@Delete()
async deleteUserRoles(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() dto: DeleteUserRoleDto,
) {
return this.userRoleService.deleteUserRole(userId, dto.roleId);
}
}
@Delete()
async deleteUserRoles(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() dto: DeleteUserRoleDto,
) {
return this.userRoleService.deleteUserRole(userId, dto.roleId);
}
}

View File

@@ -1,69 +1,76 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post, Put, Query } from "@nestjs/common";
import { ListDto } from "../dto/admin-user/list.dto";
import { CreateDto } from "../dto/admin-user/create.dto";
import { UserService } from "src/user/user.service";
import { UpdateDto } from "../dto/admin-user/update.dto";
import { UpdatePasswordDto } from "../dto/admin-user/update-password.dto";
import { RemoveUserDto } from "../dto/admin-user/remove.dto";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
Put,
Query,
} from '@nestjs/common';
import { ListDto } from '../dto/admin-user/list.dto';
import { CreateDto } from '../dto/admin-user/create.dto';
import { UserService } from 'src/user/user.service';
import { UpdateDto } from '../dto/admin-user/update.dto';
import { UpdatePasswordDto } from '../dto/admin-user/update-password.dto';
import { RemoveUserDto } from '../dto/admin-user/remove.dto';
@Controller('admin/user')
export class AdminUserController {
constructor(private readonly userService: UserService) {}
constructor(
private readonly userService: UserService,
) { }
@Get()
async list(@Query() listDto: ListDto) {
return this.userService.list(listDto.page, listDto.pageSize);
}
@Get()
async list(
@Query() listDto: ListDto
) {
return this.userService.list(listDto.page, listDto.pageSize);
}
@Get(':userId')
async get(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
) {
return this.userService.findOne({ userId });
}
@Get(':userId')
async get(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
) {
return this.userService.findOne({ userId });
}
@Post()
async create(@Body() createDto: CreateDto) {
return this.userService.create({
...createDto,
...(createDto.password &&
(() => {
const salt = this.userService.generateSalt();
return {
salt,
password_hash: this.userService.hashPassword(
createDto.password,
salt,
),
};
})()),
});
}
@Post()
async create(
@Body() createDto: CreateDto
) {
return this.userService.create({
...createDto,
...createDto.password && (() => {
const salt = this.userService.generateSalt();
return {
salt,
password_hash: this.userService.hashPassword(createDto.password, salt),
}
})(),
});
}
@Put(':userId')
async update(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() updateDto: UpdateDto,
) {
return this.userService.update(userId, updateDto);
}
@Put(':userId')
async update(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() updateDto: UpdateDto,
) {
return this.userService.update(userId, updateDto);
}
@Delete(':userId')
async delete(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Query() dto: RemoveUserDto,
) {
return this.userService.delete(userId, dto.soft);
}
@Delete(':userId')
async delete(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Query() dto: RemoveUserDto,
) {
return this.userService.delete(userId, dto.soft);
}
@Post(':userId/password')
async setPassword(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() updatePasswordDto: UpdatePasswordDto,
) {
return this.userService.setPassword(userId, updatePasswordDto.password);
}
}
@Post(':userId/password')
async setPassword(
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
@Body() updatePasswordDto: UpdatePasswordDto,
) {
return this.userService.setPassword(userId, updatePasswordDto.password);
}
}

View File

@@ -1,45 +1,45 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post, Put } from "@nestjs/common";
import { CreateBlogDto } from "src/admin/dto/admin-web/create-blog.dto";
import { BlogService } from "src/blog/blog.service";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
Put,
} from '@nestjs/common';
import { CreateBlogDto } from 'src/admin/dto/admin-web/create-blog.dto';
import { BlogService } from 'src/blog/blog.service';
@Controller('/admin/web/blog')
export class AdminWebBlogController {
constructor(private readonly adminWebBlogService: BlogService) {}
constructor(
private readonly adminWebBlogService: BlogService,
) { }
@Get()
async list() {
return this.adminWebBlogService.list();
}
@Get()
async list() {
return this.adminWebBlogService.list();
}
@Post()
async create(@Body() dto: CreateBlogDto) {
return this.adminWebBlogService.create(dto);
}
@Post()
async create(
@Body() dto: CreateBlogDto,
) {
return this.adminWebBlogService.create(dto);
}
@Put(':id')
async update(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
@Body() dto: CreateBlogDto,
) {
return this.adminWebBlogService.update(id, dto);
}
@Put(':id')
async update(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
@Body() dto: CreateBlogDto,
) {
return this.adminWebBlogService.update(id, dto);
}
@Get(':id')
async get(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.adminWebBlogService.findById(id);
}
@Get(':id')
async get(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
) {
return this.adminWebBlogService.findById(id);
}
@Delete(':id')
async remove(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
) {
return this.adminWebBlogService.remove(id);
}
}
@Delete(':id')
async remove(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.adminWebBlogService.remove(id);
}
}

View File

@@ -1,41 +1,45 @@
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post, Put } from "@nestjs/common";
import { CreateResourceDto } from "src/admin/dto/admin-web/create-resource.dto";
import { ResourceService } from "src/resource/resource.service";
import {
Body,
Controller,
Delete,
Get,
Param,
ParseUUIDPipe,
Post,
Put,
} from '@nestjs/common';
import { CreateResourceDto } from 'src/admin/dto/admin-web/create-resource.dto';
import { ResourceService } from 'src/resource/resource.service';
@Controller('/admin/web/resource')
export class AdminWebResourceController {
constructor(private readonly resourceService: ResourceService) {}
constructor(
private readonly resourceService: ResourceService,
) { }
@Get()
async list() {
return this.resourceService.findAll();
}
@Get()
async list() {
return this.resourceService.findAll();
}
@Get(':id')
async get(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.resourceService.findById(id);
}
@Get(':id')
async get(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.resourceService.findById(id);
}
@Post()
async create(@Body() data: CreateResourceDto) {
return this.resourceService.create(data);
}
@Post()
async create(@Body() data: CreateResourceDto) {
return this.resourceService.create(data);
}
@Put(':id')
async update(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
@Body() data: CreateResourceDto,
) {
return this.resourceService.update(id, data);
}
@Put(':id')
async update(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
@Body() data: CreateResourceDto
) {
return this.resourceService.update(id, data);
}
@Delete(':id')
async delete(
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
) {
return this.resourceService.delete(id);
}
}
@Delete(':id')
async delete(@Param('id', new ParseUUIDPipe({ version: '4' })) id: string) {
return this.resourceService.delete(id);
}
}

View File

@@ -1,9 +1,9 @@
import { IsString } from "class-validator";
import { IsString } from 'class-validator';
export class CreatePermissionDto {
@IsString()
name: string
@IsString()
name: string;
@IsString()
description: string;
}
@IsString()
description: string;
}

View File

@@ -1,8 +1,8 @@
import { ArrayMinSize, IsArray, IsUUID } from "class-validator";
import { ArrayMinSize, IsArray, IsUUID } from 'class-validator';
export class DeleteRolePermissionsDto {
@IsArray()
@ArrayMinSize(1)
@IsUUID('4', { each: true })
permissionIds: string[];
}
@IsArray()
@ArrayMinSize(1)
@IsUUID('4', { each: true })
permissionIds: string[];
}

View File

@@ -1,8 +1,8 @@
import { ArrayMinSize, IsArray, IsUUID } from "class-validator";
import { ArrayMinSize, IsArray, IsUUID } from 'class-validator';
export class SetRolePermissionsDto {
@IsArray()
@ArrayMinSize(1)
@IsUUID('4', { each: true })
permissionIds: string[];
}
@IsArray()
@ArrayMinSize(1)
@IsUUID('4', { each: true })
permissionIds: string[];
}

View File

@@ -1,9 +1,9 @@
import { IsString } from "class-validator";
import { IsString } from 'class-validator';
export class CreateRoleDto {
@IsString()
name: string
@IsString()
name: string;
@IsString()
localName: string;
}
@IsString()
localName: string;
}

View File

@@ -1,13 +1,13 @@
import { IsBoolean, IsDateString, IsOptional, IsUUID } from "class-validator";
import { IsBoolean, IsDateString, IsOptional, IsUUID } from 'class-validator';
export class CreateUserRoleDto {
@IsUUID('4')
roleId: string;
@IsUUID('4')
roleId: string;
@IsBoolean()
isEnabled: boolean;
@IsBoolean()
isEnabled: boolean;
@IsOptional()
@IsDateString()
expiredAt?: Date;
}
@IsOptional()
@IsDateString()
expiredAt?: Date;
}

View File

@@ -1,6 +1,6 @@
import { IsUUID } from "class-validator";
import { IsUUID } from 'class-validator';
export class DeleteUserRoleDto {
@IsUUID('4')
roleId: string;
}
@IsUUID('4')
roleId: string;
}

View File

@@ -1,31 +1,32 @@
import { IsString, Length, Matches, ValidateIf } from "class-validator";
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.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.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.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.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;
}
@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;
}

View File

@@ -1,5 +1,3 @@
import { PaginationDto } from "../common/pagination.dto";
import { PaginationDto } from '../common/pagination.dto';
export class ListDto extends PaginationDto {
}
export class ListDto extends PaginationDto {}

View File

@@ -1,8 +1,8 @@
import { Transform } from "class-transformer";
import { IsBoolean } from "class-validator";
import { Transform } from 'class-transformer';
import { IsBoolean } from 'class-validator';
export class RemoveUserDto {
@Transform(({ value }) => value === 'true')
@IsBoolean({ message: '需指定删除类型' })
soft: boolean;
}
@Transform(({ value }) => value === 'true')
@IsBoolean({ message: '需指定删除类型' })
soft: boolean;
}

View File

@@ -1,10 +1,11 @@
import { IsString, Length, Matches } from "class-validator";
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;
}
@IsString({ message: '密码不得为空' })
@Length(6, 32, { message: '密码长度只能为6~32' })
@Matches(
/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/,
{ message: '密码必须包含字母和数字且长度在6~32之间' },
)
password: string;
}

View File

@@ -1,29 +1,35 @@
import { IsEmail, IsOptional, IsString, Length, Matches } from "class-validator";
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(4, 32, { message: '用户名长度只能为4~32' })
username: string;
@IsString({ message: '昵称不得为空' })
@Length(1, 30, { message: '昵称长度只能为1~30' })
nickname: 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()
@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;
}
@IsOptional() // 标记字段为可选
@IsString({ message: '手机号不得为空', always: false })
@Matches(/^1[3456789]\d{9}$/, {
message: '请输入有效的手机号码',
// 仅在值不为 null 或 undefined 时验证
always: false,
})
phone?: string;
}

View File

@@ -1,12 +1,12 @@
import { IsString } from "class-validator";
import { IsString } from 'class-validator';
export class CreateBlogDto {
@IsString()
title: string;
@IsString()
title: string;
@IsString()
description: string;
@IsString()
description: string;
@IsString()
contentUrl: string;
}
@IsString()
contentUrl: string;
}

View File

@@ -1,28 +1,28 @@
import { Type } from "class-transformer";
import { IsString, ValidateNested } from "class-validator";
import { Type } from 'class-transformer';
import { IsString, ValidateNested } from 'class-validator';
class ResourceTagDto {
@IsString()
name: string;
@IsString()
type: string;
@IsString()
name: string;
@IsString()
type: string;
}
export class CreateResourceDto {
@IsString()
title: string;
@IsString()
title: string;
@IsString()
description: string;
@IsString()
description: string;
@IsString()
imageUrl: string;
@IsString()
imageUrl: string;
@IsString()
link: string;
@IsString()
link: string;
@ValidateNested({ each: true })
@Type(() => ResourceTagDto)
tags: ResourceTagDto[];
}
@ValidateNested({ each: true })
@Type(() => ResourceTagDto)
tags: ResourceTagDto[];
}

View File

@@ -1,16 +1,16 @@
import { Type } from 'class-transformer';
import { IsInt, IsOptional, Max, Min } from 'class-validator';
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)
page?: number = 1;
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
pageSize?: number = 20;
}
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
pageSize?: number = 20;
}