2022-03-03 13:38:39 +01:00
|
|
|
import { Exclude } from 'class-transformer';
|
2022-03-12 15:10:22 +01:00
|
|
|
import {
|
2022-03-21 17:21:03 +01:00
|
|
|
IsAlphanumeric,
|
|
|
|
|
IsArray,
|
|
|
|
|
IsInt,
|
|
|
|
|
IsNotEmpty,
|
2022-03-12 15:10:22 +01:00
|
|
|
IsOptional,
|
2022-03-21 17:21:03 +01:00
|
|
|
IsString,
|
|
|
|
|
Length
|
2022-03-12 15:10:22 +01:00
|
|
|
} from 'class-validator';
|
|
|
|
|
import { Roles } from '../dto/roles.dto';
|
2022-02-26 16:06:32 +01:00
|
|
|
|
2022-03-21 17:21:03 +01:00
|
|
|
// Match this with user validators in frontend
|
|
|
|
|
// (Not security focused, but it tells the user what is wrong)
|
2022-02-26 16:06:32 +01:00
|
|
|
|
2022-03-21 17:21:03 +01:00
|
|
|
export class SimpleUsername {
|
2022-02-26 16:06:32 +01:00
|
|
|
@IsNotEmpty()
|
2022-03-12 16:25:15 +01:00
|
|
|
@IsString()
|
2022-03-21 17:21:03 +01:00
|
|
|
@Length(4, 32)
|
|
|
|
|
@IsAlphanumeric()
|
2022-02-26 16:06:32 +01:00
|
|
|
username: string;
|
2022-03-21 17:21:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-21 23:23:32 +01:00
|
|
|
// Add a user object with just the username and roles for jwt
|
|
|
|
|
export class RoledUser extends SimpleUsername {
|
|
|
|
|
@IsArray()
|
|
|
|
|
@IsString({ each: true })
|
|
|
|
|
roles: Roles;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-21 17:21:03 +01:00
|
|
|
// Actual entity that goes in the db
|
2022-03-21 23:23:32 +01:00
|
|
|
export class EUser extends RoledUser {
|
2022-03-21 17:21:03 +01:00
|
|
|
@IsOptional()
|
|
|
|
|
@IsInt()
|
|
|
|
|
id?: number;
|
2022-02-26 16:06:32 +01:00
|
|
|
|
|
|
|
|
@IsOptional()
|
2022-02-26 18:16:28 +01:00
|
|
|
@Exclude()
|
2022-03-12 16:25:15 +01:00
|
|
|
@IsString()
|
2022-02-26 16:06:32 +01:00
|
|
|
password?: string;
|
|
|
|
|
}
|