mirror of
https://github.com/CaramelFur/Picsur.git
synced 2026-09-01 03:58:26 +02:00
relocate validator composer
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
|
||||
export const ComposeValidators = (...validators: PropertyDecorator[]): () => PropertyDecorator => {
|
||||
return () => {
|
||||
const decorators = [...validators];
|
||||
|
||||
return (target: Object, propertyKey: string | symbol): void => {
|
||||
decorators.forEach((decorator) => decorator(target, propertyKey));
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IsInt, IsNotEmpty, IsOptional, Min } from 'class-validator';
|
||||
import { ComposeValidators } from './compose.validator';
|
||||
import { CombinePDecorators } from '../util/decorator';
|
||||
|
||||
export const EntityID = ComposeValidators(IsOptional(), IsInt(), Min(0));
|
||||
export const EntityIDRequired = ComposeValidators(IsNotEmpty(), IsInt(), Min(0));
|
||||
export const EntityID = CombinePDecorators(IsOptional(), IsInt(), Min(0));
|
||||
export const EntityIDRequired = CombinePDecorators(IsNotEmpty(), IsInt(), Min(0));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsDefined, IsInt, Min } from 'class-validator';
|
||||
import { ComposeValidators } from './compose.validator';
|
||||
import { CombinePDecorators } from '../util/decorator';
|
||||
|
||||
export const IsPosInt = ComposeValidators(IsInt(), Min(0), IsDefined());
|
||||
export const IsPosInt = CombinePDecorators(IsInt(), Min(0), IsDefined());
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IsAlphanumeric, IsNotEmpty, IsString, Length } from 'class-validator';
|
||||
import { ComposeValidators } from './compose.validator';
|
||||
import { CombinePDecorators } from '../util/decorator';
|
||||
|
||||
export const IsRoleName = ComposeValidators(
|
||||
export const IsRoleName = CombinePDecorators(
|
||||
IsNotEmpty(),
|
||||
IsString(),
|
||||
Length(4, 32),
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
IsNotEmpty,
|
||||
IsString
|
||||
} from 'class-validator';
|
||||
import { ComposeValidators } from './compose.validator';
|
||||
import { CombinePDecorators } from '../util/decorator';
|
||||
|
||||
export const IsStringList = ComposeValidators(
|
||||
export const IsStringList = CombinePDecorators(
|
||||
IsArray(),
|
||||
IsString({ each: true }),
|
||||
IsNotEmpty({ each: true }),
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { IsAlphanumeric, IsNotEmpty, IsString, Length } from 'class-validator';
|
||||
import { ComposeValidators } from './compose.validator';
|
||||
import { CombinePDecorators } from '../util/decorator';
|
||||
|
||||
// Match this with user validators in frontend
|
||||
// (Frontend is not security focused, but it tells the user what is wrong)
|
||||
|
||||
export const IsUsername = ComposeValidators(
|
||||
export const IsUsername = CombinePDecorators(
|
||||
IsNotEmpty(),
|
||||
IsString(),
|
||||
Length(4, 32),
|
||||
IsAlphanumeric(),
|
||||
);
|
||||
|
||||
export const IsPlainTextPwd = ComposeValidators(
|
||||
export const IsPlainTextPwd = CombinePDecorators(
|
||||
IsNotEmpty(),
|
||||
IsString(),
|
||||
Length(4, 1024),
|
||||
|
||||
Reference in New Issue
Block a user