62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import {
|
|
IsEnum,
|
|
IsInt,
|
|
IsNotEmpty,
|
|
IsObject
|
|
} from "class-validator";
|
|
import { Permission } from '../entities/Permission';
|
|
import { PermissionAction } from '../enums/PermissionAction';
|
|
import { PermissionTarget } from '../enums/PermissionTargets';
|
|
import { ResponseObjectType } from '../enums/ResponseObjectType';
|
|
import { IResponse } from './IResponse';
|
|
import { ResponsePrincipal } from './ResponsePrincipal';
|
|
|
|
/**
|
|
* Defines the permission response.
|
|
*/
|
|
export class ResponsePermission implements IResponse {
|
|
/**
|
|
* The responseType.
|
|
* This contains the type of class/entity this response contains.
|
|
*/
|
|
responseType: ResponseObjectType = ResponseObjectType.PERMISSION;
|
|
|
|
/**
|
|
* The permission's id.
|
|
*/
|
|
@IsInt()
|
|
id: number;;
|
|
|
|
/**
|
|
* The permissions's principal.
|
|
*/
|
|
@IsObject()
|
|
@IsNotEmpty()
|
|
principal: ResponsePrincipal;
|
|
|
|
/**
|
|
* The permissions's target.
|
|
*/
|
|
@IsNotEmpty()
|
|
@IsEnum(PermissionTarget)
|
|
target: PermissionTarget;
|
|
|
|
/**
|
|
* The permissions's action.
|
|
*/
|
|
@IsNotEmpty()
|
|
@IsEnum(PermissionAction)
|
|
action: PermissionAction;
|
|
|
|
/**
|
|
* Creates a ResponsePermission object from a permission.
|
|
* @param permission The permission the response shall be build for.
|
|
*/
|
|
public constructor(permission: Permission) {
|
|
this.id = permission.id;
|
|
this.principal = permission.principal.toResponse();
|
|
this.target = permission.target;
|
|
this.action = permission.action;
|
|
}
|
|
}
|