refactor: 重构配置模块

This commit is contained in:
2024-10-26 17:37:09 +08:00
parent 0283e018de
commit 5eb78c35c2
22 changed files with 1110 additions and 833 deletions

View File

@@ -32,7 +32,8 @@ export class ConfigService {
await this.prisma.sysConfig.create({ data });
}
async findAll({ page, pageSize }: QueryListDto): Promise<QueryListResult> {
async findAll(dto: QueryListDto): Promise<QueryListResult> {
const { page, pageSize, key, value } = dto;
const query: Prisma.SysConfigFindManyArgs = {
select: {
key: true,
@@ -41,6 +42,10 @@ export class ConfigService {
},
skip: pageSize * (page - 1),
take: pageSize,
where: {
...(key && { key: { contains: key } }),
...(value && { value: { contains: value } }),
},
};
const [list, count] = await this.prisma.$transaction([

View File

@@ -1,3 +1,10 @@
import { PaginationDto } from 'src/common/dto/pagination.dto';
import { IsOptional } from 'class-validator';
export class QueryListDto extends PaginationDto {}
export class QueryListDto extends PaginationDto {
@IsOptional()
key?: string;
@IsOptional()
value?: string;
}

View File

@@ -1,3 +1,16 @@
import { PaginationDto } from 'src/common/dto/pagination.dto';
import { IsInt, IsOptional } from 'class-validator';
import { Type } from 'class-transformer';
export class QueryListDto extends PaginationDto {}
export class QueryListDto extends PaginationDto {
@IsOptional()
code?: string;
@IsOptional()
name?: string;
@IsOptional()
@Type(() => Number)
@IsInt()
status?: number;
}

View File

@@ -25,15 +25,15 @@ export class RoleService {
await this.prisma.sysRole.create({ data });
}
async findPage({ page, pageSize }: QueryListDto): Promise<QueryListResult> {
async findPage(dto: QueryListDto): Promise<QueryListResult> {
const { page, pageSize, code, status, name } = dto;
const query: Prisma.SysRoleFindManyArgs = {
skip: pageSize * (page - 1),
take: pageSize,
select: {
id: true,
name: true,
code: true,
status: true,
where: {
...(code && { code: { contains: code } }),
...(!isNaN(status) && { status }),
...(name && { name: { contains: name } }),
},
};
const [list, count] = await this.prisma.$transaction([