feat: 系统资源表
This commit is contained in:
@@ -6,7 +6,7 @@ import { PrismaService } from '@/prisma/prisma.service';
|
||||
export class PermissionService {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async getMenu(id: string) {
|
||||
async getRoleMenus(roleId: string) {
|
||||
const menuIds = await this.prisma.sysResourcePermission.findMany({
|
||||
select: {
|
||||
resourceId: true,
|
||||
@@ -14,7 +14,7 @@ export class PermissionService {
|
||||
where: {
|
||||
permission: {
|
||||
sysRolePermission: {
|
||||
some: { roleId: id },
|
||||
some: { roleId },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -23,11 +23,11 @@ export class PermissionService {
|
||||
return menuIds.map((item) => item.resourceId);
|
||||
}
|
||||
|
||||
async grantMenu(id: string, { menuIds }: GrantMenuDto) {
|
||||
async assignMenus(roleId: string, { menuIds }: GrantMenuDto) {
|
||||
await this.prisma.$transaction(async (prisma) => {
|
||||
// 删除角色对应的权限
|
||||
await prisma.sysRolePermission.deleteMany({
|
||||
where: { roleId: id },
|
||||
where: { roleId },
|
||||
});
|
||||
// 通过菜单id 找出所有权限id
|
||||
const rolePermIds = await prisma.sysResourcePermission.findMany({
|
||||
@@ -37,7 +37,7 @@ export class PermissionService {
|
||||
// 根据权限id 关联菜单和权限
|
||||
if (rolePermIds.length > 0) {
|
||||
await prisma.sysRolePermission.createMany({
|
||||
data: rolePermIds.map((item) => ({ ...item, roleId: id })),
|
||||
data: rolePermIds.map((item) => ({ ...item, roleId })),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user