Added class validation for the enum

ref #6
This commit is contained in:
Nicolai Ort 2020-12-18 19:49:39 +01:00
parent 595a9213c1
commit 2240a45a91
5 changed files with 13 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { import {
IsEnum,
IsInt, IsInt,
IsNotEmpty IsNotEmpty
} from "class-validator"; } from "class-validator";
@ -25,12 +26,14 @@ export class CreatePermission {
* The permissions's target. * The permissions's target.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionTarget)
target: PermissionTarget; target: PermissionTarget;
/** /**
* The permissions's action. * The permissions's action.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionAction)
action: PermissionAction; action: PermissionAction;
/** /**

View File

@ -1,4 +1,5 @@
import { import {
IsEnum,
IsInt, IsInt,
IsNotEmpty IsNotEmpty
} from "class-validator"; } from "class-validator";
@ -29,12 +30,14 @@ export class Permission {
*/ */
@Column({ type: 'varchar' }) @Column({ type: 'varchar' })
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionTarget)
target: PermissionTarget; target: PermissionTarget;
/** /**
* The action type * The action type
*/ */
@Column({ type: 'varchar' }) @Column({ type: 'varchar' })
@IsEnum(PermissionAction)
action: PermissionAction; action: PermissionAction;
/** /**

View File

@ -1,6 +1,6 @@
export enum PermissionAction { export enum PermissionAction {
READ = 'READ', GET = 'GET',
ADD = 'ADD', CREATE = 'CREATE',
UPDATE = 'UPDATE', UPDATE = 'UPDATE',
DELETE = 'DELETE' DELETE = 'DELETE'
} }

View File

@ -4,5 +4,6 @@ export enum PermissionTarget {
TEAM = 'RUNNERTEAM', TEAM = 'RUNNERTEAM',
TRACK = 'TRACK', TRACK = 'TRACK',
USER = 'USER', USER = 'USER',
GROUP = 'USERGROUP' GROUP = 'USERGROUP',
PERMISSION = 'PERMISSION'
} }

View File

@ -1,4 +1,5 @@
import { import {
IsEnum,
IsInt, IsInt,
IsNotEmpty, IsNotEmpty,
IsObject IsObject
@ -29,12 +30,14 @@ export class ResponsePermission {
* The permissions's target. * The permissions's target.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionTarget)
target: PermissionTarget; target: PermissionTarget;
/** /**
* The permissions's action. * The permissions's action.
*/ */
@IsNotEmpty() @IsNotEmpty()
@IsEnum(PermissionAction)
action: PermissionAction; action: PermissionAction;
public constructor(permission: Permission) { public constructor(permission: Permission) {