clean up validation, still not happy

This commit is contained in:
rubikscraft
2022-04-02 23:25:49 +02:00
parent 805ff8ab0e
commit bcd427f5a7
43 changed files with 307 additions and 277 deletions

View File

@@ -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;
}