parent
93692ec255
commit
2ac9d3e977
@ -1,7 +1,7 @@
|
|||||||
import { IsInt, IsNotEmpty, IsObject } from 'class-validator';
|
import { IsInt, IsNotEmpty, IsObject } from 'class-validator';
|
||||||
import { getConnectionManager } from 'typeorm';
|
import { getConnectionManager } from 'typeorm';
|
||||||
import { PermissionNeedsPrincipalError } from '../../../errors/PermissionErrors';
|
import { PermissionNeedsPrincipalError } from '../../../errors/PermissionErrors';
|
||||||
import { PrincipalNotFoundError, PrincipalWrongTypeError } from '../../../errors/PrincipalErrors';
|
import { PrincipalNotFoundError } from '../../../errors/PrincipalErrors';
|
||||||
import { Permission } from '../../entities/Permission';
|
import { Permission } from '../../entities/Permission';
|
||||||
import { Principal } from '../../entities/Principal';
|
import { Principal } from '../../entities/Principal';
|
||||||
import { PermissionAction } from '../../enums/PermissionAction';
|
import { PermissionAction } from '../../enums/PermissionAction';
|
||||||
@ -20,12 +20,11 @@ export class UpdatePermission {
|
|||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The updated permissions's principal.
|
* The updated permissions's principal's id.
|
||||||
* Just has to contain the principal's id -everything else won't be checked or changed.
|
|
||||||
*/
|
*/
|
||||||
@IsObject()
|
@IsObject()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
principal: Principal;
|
principal: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The permissions's target.
|
* The permissions's target.
|
||||||
@ -57,12 +56,8 @@ export class UpdatePermission {
|
|||||||
if (this.principal === undefined || this.principal === null) {
|
if (this.principal === undefined || this.principal === null) {
|
||||||
throw new PermissionNeedsPrincipalError();
|
throw new PermissionNeedsPrincipalError();
|
||||||
}
|
}
|
||||||
if (!isNaN(this.principal.id)) {
|
let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal });
|
||||||
let principal = await getConnectionManager().get().getRepository(Principal).findOne({ id: this.principal.id });
|
|
||||||
if (!principal) { throw new PrincipalNotFoundError(); }
|
if (!principal) { throw new PrincipalNotFoundError(); }
|
||||||
return principal;
|
return principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new PrincipalWrongTypeError();
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user