2022-03-03 13:38:39 +01:00
|
|
|
import { Exclude } from 'class-transformer';
|
2022-03-24 19:56:26 +01:00
|
|
|
import { IsDefined, IsOptional, IsString } from 'class-validator';
|
2022-03-23 11:17:41 +01:00
|
|
|
import { EntityID } from '../validators/entity-id.validator';
|
2022-03-24 19:56:26 +01:00
|
|
|
import { IsStringList } from '../validators/string-list.validator';
|
2022-03-23 11:17:41 +01:00
|
|
|
import { IsPlainTextPwd, IsUsername } from '../validators/user.validators';
|
2022-02-26 16:06:32 +01:00
|
|
|
|
2022-03-27 22:48:10 +02:00
|
|
|
// This entity is build from multiple smaller enitities
|
|
|
|
|
// Theses smaller entities are used in other places
|
|
|
|
|
|
2022-03-23 11:17:41 +01:00
|
|
|
export class UsernameUser {
|
|
|
|
|
@IsUsername()
|
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
|
2022-03-23 11:17:41 +01:00
|
|
|
export class NamePassUser extends UsernameUser {
|
|
|
|
|
@IsPlainTextPwd()
|
2022-03-21 17:21:03 +01:00
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-21 23:23:32 +01:00
|
|
|
// Add a user object with just the username and roles for jwt
|
2022-03-23 11:17:41 +01:00
|
|
|
export class NameRolesUser extends UsernameUser {
|
2022-03-24 19:56:26 +01:00
|
|
|
@IsDefined()
|
|
|
|
|
@IsStringList()
|
|
|
|
|
roles: string[];
|
2022-03-21 23:23:32 +01:00
|
|
|
}
|
|
|
|
|
|
2022-03-21 17:21:03 +01:00
|
|
|
// Actual entity that goes in the db
|
2022-03-23 11:17:41 +01:00
|
|
|
export class EUser extends NameRolesUser {
|
|
|
|
|
@EntityID()
|
2022-03-21 17:21:03 +01:00
|
|
|
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;
|
|
|
|
|
}
|