parent
93692ec255
commit
6b6f345618
|
@ -1,7 +1,7 @@
|
|||
import { IsInt, IsNotEmpty, IsObject } from 'class-validator';
|
||||
import { IsInt, IsNotEmpty, IsPositive } 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;
|
||||
@IsInt()
|
||||
@IsPositive()
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue