From 75fb55679674ff3bffe48f5593ebcee599eaffb2 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Tue, 10 Sep 2024 17:11:15 +0200 Subject: [PATCH] permission change length != 0 --- src/command/rolePermissionCommandHandler.ts | 9 ++++++--- src/command/userPermissionCommandHandler.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/command/rolePermissionCommandHandler.ts b/src/command/rolePermissionCommandHandler.ts index 8502171..e1d5e2c 100644 --- a/src/command/rolePermissionCommandHandler.ts +++ b/src/command/rolePermissionCommandHandler.ts @@ -27,9 +27,12 @@ export default abstract class RolePermissionCommandHandler { .transaction(async (manager) => { let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateRolePermissions.permissions); let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateRolePermissions.permissions); - - await this.updatePermissionsAdd(manager, updateRolePermissions.roleId, newPermissions); - await this.updatePermissionsRemove(manager, updateRolePermissions.roleId, removePermissions); + if (newPermissions.length != 0) { + await this.updatePermissionsAdd(manager, updateRolePermissions.roleId, newPermissions); + } + if (removePermissions.length != 0) { + await this.updatePermissionsRemove(manager, updateRolePermissions.roleId, removePermissions); + } }) .then(() => {}) .catch((err) => { diff --git a/src/command/userPermissionCommandHandler.ts b/src/command/userPermissionCommandHandler.ts index f447b0b..8006ce2 100644 --- a/src/command/userPermissionCommandHandler.ts +++ b/src/command/userPermissionCommandHandler.ts @@ -27,8 +27,12 @@ export default abstract class UserPermissionCommandHandler { let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateUserPermissions.permissions); let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateUserPermissions.permissions); - await this.updatePermissionsAdd(manager, updateUserPermissions.userId, newPermissions); - await this.updatePermissionsRemove(manager, updateUserPermissions.userId, removePermissions); + if (newPermissions.length != 0) { + await this.updatePermissionsAdd(manager, updateUserPermissions.userId, newPermissions); + } + if (removePermissions.length != 0) { + await this.updatePermissionsRemove(manager, updateUserPermissions.userId, removePermissions); + } }) .then(() => {}) .catch((err) => {