refactor: 用户管理重构优化
This commit is contained in:
2
server/prisma/migrations/20241026052827_/migration.sql
Normal file
2
server/prisma/migrations/20241026052827_/migration.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "sys_menu" ADD COLUMN "sort" INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -21,7 +21,7 @@ model SysUser {
|
||||
status Int @default(0) @db.SmallInt /// 用户状态
|
||||
avatarId Int? @map("avatar_id") /// 用户头像id
|
||||
avatar Files? @relation(fields: [avatarId], references: [id])
|
||||
gender Int @default(0) @db.SmallInt /// 用户性别
|
||||
gender Int @default(0) @db.SmallInt /// 用户性别 0:女 1:男 2:未知
|
||||
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||
userRole SysUserRole[]
|
||||
@@ -82,6 +82,7 @@ model SysMenu {
|
||||
name String
|
||||
url String
|
||||
parentId Int @default(0) @map("parent_id")
|
||||
sort Int @default(0)
|
||||
sysMenuPermission SysMenuPermission[]
|
||||
|
||||
@@map("sys_menu")
|
||||
|
||||
@@ -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([
|
||||
|
||||
1550
server/yarn.lock
1550
server/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user