From 2ac9d3e977b8903351e5e3185f3454b4bf7763df Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 15 Jan 2021 18:26:39 +0100 Subject: [PATCH] Refactoring: switched from objects to ids ref #90 --- src/models/actions/update/UpdatePermission.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/models/actions/update/UpdatePermission.ts b/src/models/actions/update/UpdatePermission.ts index e591e20..7803398 100644 --- a/src/models/actions/update/UpdatePermission.ts +++ b/src/models/actions/update/UpdatePermission.ts @@ -1,7 +1,7 @@ import { IsInt, IsNotEmpty, IsObject } from 'class-validator'; import { getConnectionManager } from 'typeorm'; import { PermissionNeedsPrincipalError } from '../../../errors/PermissionErrors'; -import { PrincipalNotFoundError, PrincipalWrongTypeError } from '../../../errors/PrincipalErrors'; +import { PrincipalNotFoundError } from '../../../errors/PrincipalErrors'; import { Permission } from '../../entities/Permission'; import { Principal } from '../../entities/Principal'; import { PermissionAction } from '../../enums/PermissionAction'; @@ -20,12 +20,11 @@ export class UpdatePermission { id: number; /** - * The updated permissions's principal. - * Just has to contain the principal's id -everything else won't be checked or changed. + * The updated permissions's principal's id. */ @IsObject() @IsNotEmpty() - principal: Principal; + principal: number; /** * The permissions's target. @@ -57,12 +56,8 @@ export class UpdatePermission { if (this.principal === undefined || this.principal === null) { throw new PermissionNeedsPrincipalError(); } - if (!isNaN(this.principal.id)) { - let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal.id }); - if (!principal) { throw new PrincipalNotFoundError(); } - return principal; - } - - throw new PrincipalWrongTypeError(); + let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal }); + if (!principal) { throw new PrincipalNotFoundError(); } + return principal; } } \ No newline at end of file