permission change length != 0

This commit is contained in:
Julian Krauser 2024-09-10 17:11:15 +02:00
parent d24785cd69
commit 75fb556796
2 changed files with 12 additions and 5 deletions

View file

@ -27,9 +27,12 @@ export default abstract class RolePermissionCommandHandler {
.transaction(async (manager) => { .transaction(async (manager) => {
let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateRolePermissions.permissions); let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateRolePermissions.permissions);
let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateRolePermissions.permissions); let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateRolePermissions.permissions);
if (newPermissions.length != 0) {
await this.updatePermissionsAdd(manager, updateRolePermissions.roleId, newPermissions); await this.updatePermissionsAdd(manager, updateRolePermissions.roleId, newPermissions);
await this.updatePermissionsRemove(manager, updateRolePermissions.roleId, removePermissions); }
if (removePermissions.length != 0) {
await this.updatePermissionsRemove(manager, updateRolePermissions.roleId, removePermissions);
}
}) })
.then(() => {}) .then(() => {})
.catch((err) => { .catch((err) => {

View file

@ -27,8 +27,12 @@ export default abstract class UserPermissionCommandHandler {
let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateUserPermissions.permissions); let newPermissions = PermissionHelper.getWhatToAdd(currentPermissions, updateUserPermissions.permissions);
let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateUserPermissions.permissions); let removePermissions = PermissionHelper.getWhatToRemove(currentPermissions, updateUserPermissions.permissions);
await this.updatePermissionsAdd(manager, updateUserPermissions.userId, newPermissions); if (newPermissions.length != 0) {
await this.updatePermissionsRemove(manager, updateUserPermissions.userId, removePermissions); await this.updatePermissionsAdd(manager, updateUserPermissions.userId, newPermissions);
}
if (removePermissions.length != 0) {
await this.updatePermissionsRemove(manager, updateUserPermissions.userId, removePermissions);
}
}) })
.then(() => {}) .then(() => {})
.catch((err) => { .catch((err) => {