mirror of
https://github.com/CaramelFur/Picsur.git
synced 2026-08-26 19:15:39 +02:00
change validation
This commit is contained in:
10
shared/src/validators/compose.validator.ts
Normal file
10
shared/src/validators/compose.validator.ts
Normal 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));
|
||||
};
|
||||
}
|
||||
};
|
||||
5
shared/src/validators/entity-id.validator.ts
Normal file
5
shared/src/validators/entity-id.validator.ts
Normal 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));
|
||||
18
shared/src/validators/user.validators.ts
Normal file
18
shared/src/validators/user.validators.ts
Normal 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),
|
||||
);
|
||||
Reference in New Issue
Block a user