refactor: 用户管理重构优化
This commit is contained in:
@@ -12,4 +12,8 @@ export class CreateMenuDto {
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
parentId?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
sort?: number;
|
||||
}
|
||||
|
||||
@@ -51,12 +51,7 @@ export class MenuService {
|
||||
|
||||
async getTreeMenu() {
|
||||
const query: Prisma.SysMenuFindManyArgs = {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
url: true,
|
||||
parentId: true,
|
||||
},
|
||||
orderBy: [{ sort: 'desc' }, { id: 'asc' }],
|
||||
};
|
||||
const list = await this.prisma.sysMenu.findMany(query);
|
||||
return this.generatorMenu(list);
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
import { PaginationDto } from 'src/common/dto/pagination.dto';
|
||||
import { IsOptional, IsInt } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
export class QueryListDto extends PaginationDto {}
|
||||
export class QueryListDto extends PaginationDto {
|
||||
@IsOptional()
|
||||
account?: string;
|
||||
|
||||
@IsOptional()
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
status?: number;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ export class UserService {
|
||||
await this.prisma.sysUser.create({ data });
|
||||
}
|
||||
|
||||
async findAll({ page, pageSize }: QueryListDto): Promise<QueryListResult> {
|
||||
async findAll(dto: QueryListDto): Promise<QueryListResult> {
|
||||
const { page, pageSize, account, status, name } = dto;
|
||||
const query: Prisma.SysUserFindManyArgs = {
|
||||
select: {
|
||||
id: true,
|
||||
@@ -70,6 +71,11 @@ export class UserService {
|
||||
},
|
||||
skip: pageSize * (page - 1),
|
||||
take: pageSize,
|
||||
where: {
|
||||
...(account && { account: { contains: account } }),
|
||||
...(!isNaN(status) && { status }),
|
||||
...(name && { name: { contains: name } }),
|
||||
},
|
||||
};
|
||||
|
||||
const [list, count] = await this.prisma.$transaction([
|
||||
|
||||
Reference in New Issue
Block a user