mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-13 23:35:39 +01:00
clean up validation, still not happy
This commit is contained in:
@@ -1,37 +1,32 @@
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { IsDefined, IsOptional, IsString } from 'class-validator';
|
||||
import { EntityID } from '../validators/entity-id.validator';
|
||||
import { IsOptional } from 'class-validator';
|
||||
import { IsEntityID } from '../validators/entity-id.validator';
|
||||
import { IsNotDefined } from '../validators/not-defined.validator';
|
||||
import { IsStringList } from '../validators/string-list.validator';
|
||||
import { IsPlainTextPwd, IsUsername } from '../validators/user.validators';
|
||||
|
||||
// This entity is build from multiple smaller enitities
|
||||
// Theses smaller entities are used in other places
|
||||
|
||||
export class UsernameUser {
|
||||
export class SimpleUser {
|
||||
@IsUsername()
|
||||
username: string;
|
||||
}
|
||||
|
||||
// This is a simple user object with just the username and unhashed password
|
||||
export class NamePassUser extends UsernameUser {
|
||||
@IsPlainTextPwd()
|
||||
password: string;
|
||||
}
|
||||
|
||||
// Add a user object with just the username and roles for jwt
|
||||
export class NameRolesUser extends UsernameUser {
|
||||
@IsDefined()
|
||||
@IsStringList()
|
||||
roles: string[];
|
||||
}
|
||||
|
||||
// Actual entity that goes in the db
|
||||
export class EUser extends NameRolesUser {
|
||||
@EntityID()
|
||||
id: string;
|
||||
|
||||
export class EUser {
|
||||
@IsOptional()
|
||||
@Exclude()
|
||||
@IsString()
|
||||
password?: string;
|
||||
@IsEntityID()
|
||||
id?: string;
|
||||
|
||||
@IsUsername()
|
||||
username: string;
|
||||
|
||||
@IsStringList()
|
||||
roles: string[];
|
||||
|
||||
// Because typescript does not support exact types, we have to do this stupidness
|
||||
@IsNotDefined()
|
||||
hashedPassword: undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user