Code + comment cleanup for the entities

ref #39
This commit is contained in:
2020-12-21 15:29:32 +01:00
parent a03f1a438d
commit d20d738218
21 changed files with 156 additions and 87 deletions

View File

@@ -8,7 +8,9 @@ import { PermissionAction } from '../enums/PermissionAction';
import { PermissionTarget } from '../enums/PermissionTargets';
import { Principal } from './Principal';
/**
* Defines the Permission interface.
* Defines the Permission entity.
* Permissions can be granted to principals.
* The permissions possible targets and actions are defined in enums.
*/
@Entity()
export class Permission {
@@ -20,13 +22,14 @@ export class Permission {
id: number;
/**
* The permissions principal
* The permission's principal.
*/
@ManyToOne(() => Principal, principal => principal.permissions)
principal: Principal;
/**
* The target
* The permission's target.
* This get's stored as the enum value's string representation for compatability reasons.
*/
@Column({ type: 'varchar' })
@IsNotEmpty()
@@ -34,14 +37,16 @@ export class Permission {
target: PermissionTarget;
/**
* The action type
* The permission's action.
* This get's stored as the enum value's string representation for compatability reasons.
*/
@Column({ type: 'varchar' })
@IsEnum(PermissionAction)
action: PermissionAction;
/**
* Turn this into a string for exporting (and jwts).
* Turn this into a string for exporting and jwts.
* Mainly used to shrink the size of jwts (otherwise the would contain entire objects).
*/
public toString(): string {
return this.target + ":" + this.action;