Feature/improve date validation in activity endpoints (#3489)

* Improve date validation

* Update changelog
This commit is contained in:
Thomas Kaul
2024-06-14 03:40:47 +02:00
committed by GitHub
parent 0adefe14e1
commit bf20a5de82
7 changed files with 60 additions and 4 deletions

View File

@@ -0,0 +1,16 @@
import {
ValidatorConstraint,
ValidatorConstraintInterface
} from 'class-validator';
import { format, isAfter, parseISO } from 'date-fns';
@ValidatorConstraint({ name: 'isAfter1970' })
export class IsAfter1970Constraint implements ValidatorConstraintInterface {
public defaultMessage() {
return `date must be after ${format(new Date(0), 'yyyy')}`;
}
public validate(aDateString: string) {
return isAfter(parseISO(aDateString), new Date(0));
}
}