Feature/improve date validation in activity endpoints (#3489)
* Improve date validation * Update changelog
This commit is contained in:
16
libs/common/src/lib/validator-constraints/is-after-1970.ts
Normal file
16
libs/common/src/lib/validator-constraints/is-after-1970.ts
Normal 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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user