Refactor user validation

This commit is contained in:
rubikscraft
2022-03-21 17:21:03 +01:00
parent 8c88c5f24e
commit 581be5921b
10 changed files with 161 additions and 131 deletions

View File

@@ -1,20 +1,40 @@
import { Exclude } from 'class-transformer';
import {
IsArray, IsInt, IsNotEmpty,
IsAlphanumeric,
IsArray,
IsInt,
IsNotEmpty,
IsOptional,
IsString
IsString,
Length
} from 'class-validator';
import { Roles } from '../dto/roles.dto';
export class EUser {
// Match this with user validators in frontend
// (Not security focused, but it tells the user what is wrong)
export class SimpleUsername {
@IsNotEmpty()
@IsString()
@Length(4, 32)
@IsAlphanumeric()
username: string;
}
// This is a simple user object with just the username and unhashed password
export class SimpleUser extends SimpleUsername {
@IsNotEmpty()
@IsString()
@Length(4, 1024)
password: string;
}
// Actual entity that goes in the db
export class EUser extends SimpleUsername {
@IsOptional()
@IsInt()
id?: number;
@IsNotEmpty()
@IsString()
username: string;
@IsArray()
@IsString({ each: true })
roles: Roles;