mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-13 15:25:39 +01:00
Refactor user validation
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user