refactor:替换自增id为cuid
This commit is contained in:
@@ -9,6 +9,6 @@ export function login(data: LoginData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function grantUserRoles(userId: number, data) {
|
export function grantUserRoles(userId: string, data) {
|
||||||
return request.post('/auth/userRole/' + userId,data);
|
return request.post('/auth/userRole/' + userId,data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ export function updateMenu(data) {
|
|||||||
return request.patch('/menu/' + data.id, data);
|
return request.patch('/menu/' + data.id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteMenu(id: number) {
|
export function deleteMenu(id: string) {
|
||||||
return request.delete('/menu/' + id);
|
return request.delete('/menu/' + id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
|
||||||
export function grantPermission(id: number, menuIds: number[]) {
|
export function grantPermission(id: string, menuIds: string[]) {
|
||||||
return request.patch('/permission/' + id, { menuIds });
|
return request.patch('/permission/' + id, { menuIds });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRoleMenuIds(id: number) {
|
export function getRoleMenuIds(id: string) {
|
||||||
return request.get('/permission/' + id + '/menu');
|
return request.get('/permission/' + id + '/menu');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ export function updateRole(data) {
|
|||||||
return request.patch('/role/' + data.id, data);
|
return request.patch('/role/' + data.id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteRole(id: number) {
|
export function deleteRole(id: string) {
|
||||||
return request.delete('/role/' + id);
|
return request.delete('/role/' + id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ export function updateUser(data) {
|
|||||||
/**
|
/**
|
||||||
* 删除用户
|
* 删除用户
|
||||||
* */
|
* */
|
||||||
export function deleteUser(id: number) {
|
export function deleteUser(id: string) {
|
||||||
return request.delete('/user/' + id);
|
return request.delete('/user/' + id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,20 @@ export type IRoute = AuthParams & {
|
|||||||
icon?: string
|
icon?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
const generatorMenu = (data, parentId = 0) => {
|
const generatorMenu = (data, parentId?:string) => {
|
||||||
const menu = [];
|
const menu = [];
|
||||||
for (const item of data) {
|
for (const item of data) {
|
||||||
item.key = item.url;
|
item.key = item.url;
|
||||||
if (item.parentId === parentId) {
|
if(!parentId){
|
||||||
const children = generatorMenu(data, item.id);
|
|
||||||
if (children.length) {
|
|
||||||
item.children = children;
|
|
||||||
}
|
|
||||||
menu.push(item);
|
menu.push(item);
|
||||||
|
}else{
|
||||||
|
if (item.parentId === parentId) {
|
||||||
|
const children = generatorMenu(data, item.id);
|
||||||
|
if (children.length) {
|
||||||
|
item.children = children;
|
||||||
|
}
|
||||||
|
menu.push(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return menu;
|
return menu;
|
||||||
|
|||||||
@@ -46,13 +46,17 @@ export const createUserStore: StateCreator<IUserStore> = (set) => ({
|
|||||||
},
|
},
|
||||||
logout: async () => {
|
logout: async () => {
|
||||||
localStorage.removeItem('accessToken');
|
localStorage.removeItem('accessToken');
|
||||||
window.location.href = '/login';
|
|
||||||
set({
|
set({
|
||||||
userInfo: {
|
userInfo: {
|
||||||
permissions: [],
|
permissions: [],
|
||||||
menus:[]
|
menus:[]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (location.pathname !== '/login') {
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
-- AlterTable
|
|
||||||
ALTER TABLE "sys_menu" ADD COLUMN "sort" INTEGER NOT NULL DEFAULT 0;
|
|
||||||
@@ -1,22 +1,24 @@
|
|||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_user" (
|
CREATE TABLE "sys_user" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
"name" TEXT,
|
"name" TEXT,
|
||||||
"account" TEXT NOT NULL,
|
"account" TEXT NOT NULL,
|
||||||
"password" TEXT NOT NULL,
|
"password" TEXT NOT NULL,
|
||||||
"password_salt" TEXT NOT NULL,
|
"password_salt" TEXT NOT NULL,
|
||||||
"status" SMALLINT NOT NULL DEFAULT 0,
|
"status" SMALLINT NOT NULL DEFAULT 0,
|
||||||
"avatar_id" INTEGER,
|
"avatar_id" TEXT,
|
||||||
"gender" SMALLINT NOT NULL DEFAULT 0,
|
"gender" SMALLINT NOT NULL DEFAULT 0,
|
||||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
|
||||||
|
|
||||||
CONSTRAINT "sys_user_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "sys_user_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_role" (
|
CREATE TABLE "sys_role" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
"code" TEXT NOT NULL,
|
"code" TEXT NOT NULL,
|
||||||
"name" TEXT NOT NULL,
|
"name" TEXT NOT NULL,
|
||||||
"status" SMALLINT NOT NULL DEFAULT 0,
|
"status" SMALLINT NOT NULL DEFAULT 0,
|
||||||
@@ -26,26 +28,31 @@ CREATE TABLE "sys_role" (
|
|||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_user_role" (
|
CREATE TABLE "sys_user_role" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
"user_id" INTEGER NOT NULL,
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"role_id" INTEGER NOT NULL,
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
|
"user_id" TEXT NOT NULL,
|
||||||
|
"role_id" TEXT NOT NULL,
|
||||||
|
|
||||||
CONSTRAINT "sys_user_role_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "sys_user_role_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "files" (
|
CREATE TABLE "file" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
"name" TEXT NOT NULL,
|
"name" TEXT NOT NULL,
|
||||||
"path" TEXT NOT NULL,
|
"path" TEXT NOT NULL,
|
||||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
|
|
||||||
CONSTRAINT "files_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "file_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_permission" (
|
CREATE TABLE "sys_permission" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
"type" INTEGER NOT NULL,
|
"type" INTEGER NOT NULL,
|
||||||
|
|
||||||
CONSTRAINT "sys_permission_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "sys_permission_pkey" PRIMARY KEY ("id")
|
||||||
@@ -53,37 +60,49 @@ CREATE TABLE "sys_permission" (
|
|||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_menu" (
|
CREATE TABLE "sys_menu" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
"name" TEXT NOT NULL,
|
"name" TEXT NOT NULL,
|
||||||
"url" TEXT NOT NULL,
|
"url" TEXT NOT NULL,
|
||||||
"parent_id" INTEGER NOT NULL DEFAULT 0,
|
"parent_id" TEXT,
|
||||||
|
"sort" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
|
||||||
CONSTRAINT "sys_menu_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "sys_menu_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_menu_permission" (
|
CREATE TABLE "sys_menu_permission" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
"menu_id" INTEGER NOT NULL,
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"permission_id" INTEGER NOT NULL,
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
|
"menu_id" TEXT NOT NULL,
|
||||||
|
"permission_id" TEXT NOT NULL,
|
||||||
|
|
||||||
CONSTRAINT "sys_menu_permission_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "sys_menu_permission_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_role_permission" (
|
CREATE TABLE "sys_role_permission" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" TEXT NOT NULL,
|
||||||
"role_id" INTEGER NOT NULL,
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"permission_id" INTEGER NOT NULL,
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
|
"role_id" TEXT NOT NULL,
|
||||||
|
"permission_id" TEXT NOT NULL,
|
||||||
|
|
||||||
CONSTRAINT "sys_role_permission_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "sys_role_permission_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "sys_config" (
|
CREATE TABLE "sys_config" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||||
"key" TEXT NOT NULL,
|
"key" TEXT NOT NULL,
|
||||||
"value" TEXT NOT NULL,
|
"value" TEXT NOT NULL,
|
||||||
"remark" TEXT
|
"remark" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "sys_config_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
@@ -13,17 +13,17 @@ datasource db {
|
|||||||
|
|
||||||
// 系统用户表
|
// 系统用户表
|
||||||
model SysUser {
|
model SysUser {
|
||||||
id Int @id @default(autoincrement()) /// 主键id
|
id String @id @default(cuid()) /// 主键id
|
||||||
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
name String? /// 用户姓名
|
name String? /// 用户姓名
|
||||||
account String @unique /// 账户
|
account String @unique /// 账户
|
||||||
password String /// 密码
|
password String /// 密码
|
||||||
passwordSalt String @map("password_salt") /// 密码盐
|
passwordSalt String @map("password_salt") /// 密码盐
|
||||||
status Int @default(0) @db.SmallInt /// 用户状态
|
status Int @default(0) @db.SmallInt /// 用户状态
|
||||||
avatarId Int? @map("avatar_id") /// 用户头像id
|
avatarId String? @map("avatar_id") /// 用户头像id
|
||||||
avatar Files? @relation(fields: [avatarId], references: [id])
|
avatar File? @relation(fields: [avatarId], references: [id])
|
||||||
gender Int @default(0) @db.SmallInt /// 用户性别 0:女 1:男 2:未知
|
gender Int @default(0) @db.SmallInt /// 用户性别 0:女 1:男 2:未知
|
||||||
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
|
||||||
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
|
||||||
userRole SysUserRole[]
|
userRole SysUserRole[]
|
||||||
|
|
||||||
@@index([avatarId])
|
@@index([avatarId])
|
||||||
@@ -32,7 +32,9 @@ model SysUser {
|
|||||||
|
|
||||||
// 系统角色表
|
// 系统角色表
|
||||||
model SysRole {
|
model SysRole {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
code String @unique
|
code String @unique
|
||||||
name String
|
name String
|
||||||
status Int @default(0) @db.SmallInt /// 角色状态
|
status Int @default(0) @db.SmallInt /// 角色状态
|
||||||
@@ -44,11 +46,13 @@ model SysRole {
|
|||||||
|
|
||||||
// 用户角色关联表
|
// 用户角色关联表
|
||||||
model SysUserRole {
|
model SysUserRole {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
userId Int @map("user_id")
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
roleId Int @map("role_id")
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
user SysUser @relation(fields: [userId], references: [id], onDelete: Cascade)
|
userId String @map("user_id")
|
||||||
role SysRole @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
roleId String @map("role_id")
|
||||||
|
user SysUser @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
role SysRole @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@index([userId])
|
@@index([userId])
|
||||||
@@index([roleId])
|
@@index([roleId])
|
||||||
@@ -56,19 +60,22 @@ model SysUserRole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 文件表
|
// 文件表
|
||||||
model Files {
|
model File {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
name String /// 文件名称
|
name String /// 文件名称
|
||||||
path String
|
path String
|
||||||
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
|
||||||
sysUser SysUser[]
|
sysUser SysUser[]
|
||||||
|
|
||||||
@@map("files")
|
@@map("file")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 权限表
|
// 权限表
|
||||||
model SysPermission {
|
model SysPermission {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
type Int
|
type Int
|
||||||
sysRolePermission SysRolePermission[]
|
sysRolePermission SysRolePermission[]
|
||||||
sysMenuPermission SysMenuPermission[]
|
sysMenuPermission SysMenuPermission[]
|
||||||
@@ -78,10 +85,12 @@ model SysPermission {
|
|||||||
|
|
||||||
// 系统菜单表
|
// 系统菜单表
|
||||||
model SysMenu {
|
model SysMenu {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
name String
|
name String
|
||||||
url String
|
url String
|
||||||
parentId Int @default(0) @map("parent_id")
|
parentId String? @map("parent_id")
|
||||||
sort Int @default(0)
|
sort Int @default(0)
|
||||||
sysMenuPermission SysMenuPermission[]
|
sysMenuPermission SysMenuPermission[]
|
||||||
|
|
||||||
@@ -90,9 +99,11 @@ model SysMenu {
|
|||||||
|
|
||||||
// 菜单权限关联表
|
// 菜单权限关联表
|
||||||
model SysMenuPermission {
|
model SysMenuPermission {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
menuId Int @map("menu_id")
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
permissionId Int @map("permission_id")
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
|
menuId String @map("menu_id")
|
||||||
|
permissionId String @map("permission_id")
|
||||||
menu SysMenu @relation(fields: [menuId], references: [id], onDelete: Cascade)
|
menu SysMenu @relation(fields: [menuId], references: [id], onDelete: Cascade)
|
||||||
permission SysPermission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
permission SysPermission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@ -103,9 +114,11 @@ model SysMenuPermission {
|
|||||||
|
|
||||||
// 角色权限关联表
|
// 角色权限关联表
|
||||||
model SysRolePermission {
|
model SysRolePermission {
|
||||||
id Int @id @default(autoincrement())
|
id String @id @default(cuid()) /// 主键id
|
||||||
roleId Int @map("role_id")
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
permissionId Int @map("permission_id")
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
|
roleId String @map("role_id")
|
||||||
|
permissionId String @map("permission_id")
|
||||||
role SysRole @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
role SysRole @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
||||||
permission SysPermission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
permission SysPermission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
|
||||||
|
|
||||||
@@ -116,9 +129,12 @@ model SysRolePermission {
|
|||||||
|
|
||||||
// 系统配置
|
// 系统配置
|
||||||
model SysConfig {
|
model SysConfig {
|
||||||
key String @unique
|
id String @id @default(cuid()) /// 主键id
|
||||||
value String
|
createdAt DateTime @default(now()) @map("created_at") /// 创建时间
|
||||||
remark String?
|
updatedAt DateTime @updatedAt @map("updated_at") /// 修改时间
|
||||||
|
key String @unique
|
||||||
|
value String
|
||||||
|
remark String?
|
||||||
|
|
||||||
@@map("sys_config")
|
@@map("sys_config")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ async function main() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const menus = [
|
const menus = [
|
||||||
{ name: '用户管理', url: 'user', parentId: 0 },
|
{ name: '用户管理', url: 'user' },
|
||||||
{ name: '角色管理', url: 'role', parentId: 0 },
|
{ name: '角色管理', url: 'role' },
|
||||||
{ name: '菜单管理', url: 'menu', parentId: 0 },
|
{ name: '菜单管理', url: 'menu' },
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const menu of menus) {
|
for (const menu of menus) {
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ export class AuthController {
|
|||||||
// 授权用户角色
|
// 授权用户角色
|
||||||
@Post('userRole/:id')
|
@Post('userRole/:id')
|
||||||
grantUserRole(@Param('id') id: string, @Body() dto: UserRoleDto) {
|
grantUserRole(@Param('id') id: string, @Body() dto: UserRoleDto) {
|
||||||
return this.authService.grantUserRole(+id, dto);
|
return this.authService.grantUserRole(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 授权角色权限
|
// 授权角色权限
|
||||||
@Post('rolePermission/:id')
|
@Post('rolePermission/:id')
|
||||||
grantRolePermission(@Param('id') id: string, @Body() dto: RolePermissionDto) {
|
grantRolePermission(@Param('id') id: string, @Body() dto: RolePermissionDto) {
|
||||||
return this.authService.grantRolePermission(+id, dto);
|
return this.authService.grantRolePermission(id, dto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export class AuthService {
|
|||||||
return { accessToken };
|
return { accessToken };
|
||||||
}
|
}
|
||||||
|
|
||||||
async grantUserRole(id: number, { roleIds }: UserRoleDto) {
|
async grantUserRole(id: string, { roleIds }: UserRoleDto) {
|
||||||
const user = await this.prisma.sysUser.findUnique({
|
const user = await this.prisma.sysUser.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
@@ -96,7 +96,7 @@ export class AuthService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async grantRolePermission(id: number, { permissionIds }: RolePermissionDto) {
|
async grantRolePermission(id: string, { permissionIds }: RolePermissionDto) {
|
||||||
const role = await this.prisma.sysRole.findUnique({
|
const role = await this.prisma.sysRole.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ArrayUnique, IsInt, IsNotEmpty } from 'class-validator';
|
import { ArrayUnique, IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
export class RolePermissionDto {
|
export class RolePermissionDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsInt({ each: true })
|
@IsString({ each: true })
|
||||||
@ArrayUnique()
|
@ArrayUnique()
|
||||||
permissionIds: number[];
|
permissionIds: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { ArrayUnique, IsInt, IsNotEmpty } from 'class-validator';
|
import { ArrayUnique, IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
export class UserRoleDto {
|
export class UserRoleDto {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsInt({ each: true })
|
@IsString({ each: true })
|
||||||
@ArrayUnique()
|
@ArrayUnique()
|
||||||
roleIds: number[];
|
roleIds: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class FilesService {
|
|||||||
|
|
||||||
const filePath = await this.minioService.uploadFile(file, fileName);
|
const filePath = await this.minioService.uploadFile(file, fileName);
|
||||||
|
|
||||||
const res = await this.prisma.files.create({
|
const res = await this.prisma.file.create({
|
||||||
data: { name: fileName, path: filePath },
|
data: { name: fileName, path: filePath },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ export class CreateMenuDto {
|
|||||||
url: string;
|
url: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@IsString()
|
||||||
parentId?: number;
|
parentId?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsInt()
|
@IsInt()
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ export class MenuController {
|
|||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateMenuDto: UpdateMenuDto) {
|
update(@Param('id') id: string, @Body() updateMenuDto: UpdateMenuDto) {
|
||||||
return this.menuService.update(+id, updateMenuDto);
|
return this.menuService.update(id, updateMenuDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
remove(@Param('id') id: number) {
|
remove(@Param('id') id: string) {
|
||||||
return this.menuService.remove(id);
|
return this.menuService.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { PermissionType } from '@/common/enum';
|
|||||||
export class MenuService {
|
export class MenuService {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
findOne(params: { id?: number; excludeId?: number }) {
|
findOne(params: { id?: string; excludeId?: string }) {
|
||||||
const { id, excludeId } = params;
|
const { id, excludeId } = params;
|
||||||
return this.prisma.sysMenu.findFirst({
|
return this.prisma.sysMenu.findFirst({
|
||||||
where: {
|
where: {
|
||||||
@@ -19,7 +19,7 @@ export class MenuService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
findOneById(id: number) {
|
findOneById(id: string) {
|
||||||
return this.prisma.sysMenu.findUnique({ where: { id } });
|
return this.prisma.sysMenu.findUnique({ where: { id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,15 +35,20 @@ export class MenuService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generatorMenu(data, parentId = 0) {
|
generatorMenu(data, parentId?: string) {
|
||||||
const menu = [];
|
const menu = [];
|
||||||
for (const item of data) {
|
for (const item of data) {
|
||||||
if (item.parentId === parentId) {
|
// 不存在父id 代表是顶级菜单
|
||||||
const children = this.generatorMenu(data, item.id);
|
if (!parentId) {
|
||||||
if (children.length) {
|
|
||||||
item.children = children;
|
|
||||||
}
|
|
||||||
menu.push(item);
|
menu.push(item);
|
||||||
|
} else {
|
||||||
|
if (item.parentId === parentId) {
|
||||||
|
const children = this.generatorMenu(data, item.id);
|
||||||
|
if (children.length) {
|
||||||
|
item.children = children;
|
||||||
|
}
|
||||||
|
menu.push(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return menu;
|
return menu;
|
||||||
@@ -69,7 +74,7 @@ export class MenuService {
|
|||||||
return this.prisma.sysMenu.findMany(query);
|
return this.prisma.sysMenu.findMany(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, data: UpdateMenuDto) {
|
async update(id: string, data: UpdateMenuDto) {
|
||||||
const doesExists = await this.findOne({ id });
|
const doesExists = await this.findOne({ id });
|
||||||
if (!doesExists) {
|
if (!doesExists) {
|
||||||
throw new HttpException('菜单不存在!', HttpStatus.NOT_FOUND);
|
throw new HttpException('菜单不存在!', HttpStatus.NOT_FOUND);
|
||||||
@@ -85,7 +90,7 @@ export class MenuService {
|
|||||||
await this.prisma.sysMenu.update({ data, where: { id } });
|
await this.prisma.sysMenu.update({ data, where: { id } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(menuId: number) {
|
async remove(menuId: string) {
|
||||||
const doesExists = await this.findOneById(menuId);
|
const doesExists = await this.findOneById(menuId);
|
||||||
if (!doesExists) {
|
if (!doesExists) {
|
||||||
throw new HttpException('菜单不存在!', HttpStatus.NOT_FOUND);
|
throw new HttpException('菜单不存在!', HttpStatus.NOT_FOUND);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { IsNumber } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
|
|
||||||
export class GrantMenuDto {
|
export class GrantMenuDto {
|
||||||
@IsNumber({}, { each: true })
|
@IsString({ each: true })
|
||||||
menuIds: number[];
|
menuIds: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ export class PermissionController {
|
|||||||
constructor(private readonly permissionService: PermissionService) {}
|
constructor(private readonly permissionService: PermissionService) {}
|
||||||
|
|
||||||
@Get(':id/menu')
|
@Get(':id/menu')
|
||||||
getMenu(@Param('id') id: number) {
|
getMenu(@Param('id') id: string) {
|
||||||
return this.permissionService.getMenu(id);
|
return this.permissionService.getMenu(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
grantMenu(@Param('id') id: number, @Body() dto: GrantMenuDto) {
|
grantMenu(@Param('id') id: string, @Body() dto: GrantMenuDto) {
|
||||||
return this.permissionService.grantMenu(id, dto);
|
return this.permissionService.grantMenu(id, dto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { PrismaService } from '@/prisma/prisma.service';
|
|||||||
export class PermissionService {
|
export class PermissionService {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
constructor(private readonly prisma: PrismaService) {}
|
||||||
|
|
||||||
async getMenu(id: number) {
|
async getMenu(id: string) {
|
||||||
const menuIds = await this.prisma.sysMenuPermission.findMany({
|
const menuIds = await this.prisma.sysMenuPermission.findMany({
|
||||||
select: {
|
select: {
|
||||||
menuId: true,
|
menuId: true,
|
||||||
@@ -23,7 +23,7 @@ export class PermissionService {
|
|||||||
return menuIds.map((item) => item.menuId);
|
return menuIds.map((item) => item.menuId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async grantMenu(id: number, { menuIds }: GrantMenuDto) {
|
async grantMenu(id: string, { menuIds }: GrantMenuDto) {
|
||||||
await this.prisma.$transaction(async (prisma) => {
|
await this.prisma.$transaction(async (prisma) => {
|
||||||
// 删除角色对应的权限
|
// 删除角色对应的权限
|
||||||
await prisma.sysRolePermission.deleteMany({
|
await prisma.sysRolePermission.deleteMany({
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ export class RoleController {
|
|||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateRoleDto) {
|
update(@Param('id') id: string, @Body() dto: UpdateRoleDto) {
|
||||||
return this.roleService.update(+id, dto);
|
return this.roleService.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string) {
|
||||||
return this.roleService.remove(+id);
|
return this.roleService.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export class RoleService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, data: UpdateRoleDto) {
|
async update(id: string, data: UpdateRoleDto) {
|
||||||
const role = await this.findOne({ id });
|
const role = await this.findOne({ id });
|
||||||
if (!role)
|
if (!role)
|
||||||
throw new HttpException('角色信息不存在!', HttpStatus.NOT_FOUND);
|
throw new HttpException('角色信息不存在!', HttpStatus.NOT_FOUND);
|
||||||
@@ -71,7 +71,7 @@ export class RoleService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: number) {
|
async remove(id: string) {
|
||||||
const role = await this.findOne({ id });
|
const role = await this.findOne({ id });
|
||||||
if (!role)
|
if (!role)
|
||||||
throw new HttpException('角色信息不存在!', HttpStatus.NOT_FOUND);
|
throw new HttpException('角色信息不存在!', HttpStatus.NOT_FOUND);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
|
IsString,
|
||||||
MaxLength,
|
MaxLength,
|
||||||
MinLength,
|
MinLength,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
@@ -17,8 +18,8 @@ export class CreateUserDto {
|
|||||||
account: string;
|
account: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsString()
|
||||||
avatarId: number;
|
avatarId: string;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
|
|||||||
@@ -37,22 +37,22 @@ export class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
findOneById(@Param('id') id: number) {
|
findOneById(@Param('id') id: string) {
|
||||||
return this.userService.findOneById(id);
|
return this.userService.findOneById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/password')
|
@Patch(':id/password')
|
||||||
updatePassword(@Param('id') id: string, @Body() dto: UpdatePasswordDto) {
|
updatePassword(@Param('id') id: string, @Body() dto: UpdatePasswordDto) {
|
||||||
return this.userService.updatePassword(+id, dto);
|
return this.userService.updatePassword(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() dto: UpdateUserDto) {
|
update(@Param('id') id: string, @Body() dto: UpdateUserDto) {
|
||||||
return this.userService.update(+id, dto);
|
return this.userService.update(id, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
remove(@Param('id') id: string) {
|
remove(@Param('id') id: string) {
|
||||||
return this.userService.remove(+id);
|
return this.userService.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class UserService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneById(id: number) {
|
async findOneById(id: string) {
|
||||||
return this.prisma.sysUser.findUnique({
|
return this.prisma.sysUser.findUnique({
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -112,7 +112,7 @@ export class UserService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUserInfo(id: number, isAdmin: boolean) {
|
async getUserInfo(id: string, isAdmin: boolean) {
|
||||||
const user = await this.prisma.sysUser.findUnique({
|
const user = await this.prisma.sysUser.findUnique({
|
||||||
select: {
|
select: {
|
||||||
name: true,
|
name: true,
|
||||||
@@ -154,7 +154,7 @@ export class UserService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, data: UpdateUserDto) {
|
async update(id: string, data: UpdateUserDto) {
|
||||||
const user = await this.findOne({ id });
|
const user = await this.findOne({ id });
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new HttpException('修改失败,用户不存在!', HttpStatus.NOT_FOUND);
|
throw new HttpException('修改失败,用户不存在!', HttpStatus.NOT_FOUND);
|
||||||
@@ -178,7 +178,7 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updatePassword(
|
async updatePassword(
|
||||||
id: number,
|
id: string,
|
||||||
{ password, newPassword }: UpdatePasswordDto,
|
{ password, newPassword }: UpdatePasswordDto,
|
||||||
) {
|
) {
|
||||||
const user = await this.findOne({ id });
|
const user = await this.findOne({ id });
|
||||||
@@ -203,7 +203,7 @@ export class UserService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: number) {
|
async remove(id: string) {
|
||||||
const user = await this.findOne({ id });
|
const user = await this.findOne({ id });
|
||||||
|
|
||||||
if (!user)
|
if (!user)
|
||||||
|
|||||||
Reference in New Issue
Block a user