From b2bd6173a5b2c2fab5a259e0136486aeb92fd833 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sun, 20 Dec 2020 17:29:04 +0100 Subject: [PATCH] Moved permissions to the new put mechanism ref #39 --- src/controllers/PermissionController.ts | 2 +- src/models/actions/UpdatePermission.ts | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 6be00fd..208fe6f 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -96,7 +96,7 @@ export class PermissionController { return new ResponsePermission(existingPermission); } - await this.permissionRepository.update(oldPermission, await permission.toPermission()); + await this.permissionRepository.save(await permission.updatePermission(oldPermission)); return new ResponsePermission(await this.permissionRepository.findOne({ id: permission.id }, { relations: ['principal'] })); } diff --git a/src/models/actions/UpdatePermission.ts b/src/models/actions/UpdatePermission.ts index 26c2a83..dec0ad8 100644 --- a/src/models/actions/UpdatePermission.ts +++ b/src/models/actions/UpdatePermission.ts @@ -37,14 +37,12 @@ export class UpdatePermission { /** * Converts a Permission object based on this. */ - public async toPermission(): Promise { - let newPermission: Permission = new Permission(); + public async updatePermission(permission: Permission): Promise { + permission.principal = await this.getPrincipal(); + permission.target = this.target; + permission.action = this.action; - newPermission.principal = await this.getPrincipal(); - newPermission.target = this.target; - newPermission.action = this.action; - - return newPermission; + return permission; } /**