change validation

This commit is contained in:
rubikscraft
2022-03-23 11:17:41 +01:00
parent 0b65d496c3
commit 036f4d4e4d
17 changed files with 178 additions and 119 deletions

View File

@@ -0,0 +1,10 @@
export const ComposeValidators = (...validators: PropertyDecorator[]): () => PropertyDecorator => {
return () => {
const decorators = [...validators];
return (target: Object, propertyKey: string | symbol): void => {
decorators.forEach((decorator) => decorator(target, propertyKey));
};
}
};

View File

@@ -0,0 +1,5 @@
import { IsInt, IsNotEmpty, IsOptional, Min } from 'class-validator';
import { ComposeValidators } from './compose.validator';
export const EntityID = ComposeValidators(IsOptional(), IsInt(), Min(0));
export const EntityIDRequired = ComposeValidators(IsNotEmpty(), IsInt(), Min(0));

View File

@@ -0,0 +1,18 @@
import { IsAlphanumeric, IsNotEmpty, IsString, Length } from 'class-validator';
import { ComposeValidators } from './compose.validator';
// Match this with user validators in frontend
// (Frontend is not security focused, but it tells the user what is wrong)
export const IsUsername = ComposeValidators(
IsNotEmpty(),
IsString(),
Length(4, 32),
IsAlphanumeric(),
);
export const IsPlainTextPwd = ComposeValidators(
IsNotEmpty(),
IsString(),
Length(4, 1024),
);