parent
882065470a
commit
6a7e8ccc37
|
@ -59,6 +59,8 @@ export class PermissionController {
|
|||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
let existingPermission = await this.permissionRepository.findOne({ target: permission.target, action: permission.action, principal: permission.principal }, { relations: ['principal'] });
|
||||
if (existingPermission) { return new ResponsePermission(existingPermission); }
|
||||
|
||||
permission = await this.permissionRepository.save(permission);
|
||||
permission = await this.permissionRepository.findOne(permission, { relations: ['principal'] });
|
||||
|
@ -84,6 +86,11 @@ export class PermissionController {
|
|||
if (oldPermission.id != permission.id) {
|
||||
throw new PermissionIdsNotMatchingError();
|
||||
}
|
||||
let existingPermission = await this.permissionRepository.findOne({ target: permission.target, action: permission.action, principal: permission.principal }, { relations: ['principal'] });
|
||||
if (existingPermission) {
|
||||
await this.remove(permission.id, true);
|
||||
return new ResponsePermission(existingPermission);
|
||||
}
|
||||
|
||||
await this.permissionRepository.update(oldPermission, await permission.toPermission());
|
||||
|
||||
|
|
Loading…
Reference in New Issue