Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 29 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | registerDecorator, |
||
3 | ValidationOptions, |
||
4 | ValidationArguments |
||
5 | } from 'class-validator'; |
||
6 | |||
7 | export const DateGreaterOrEqualThan = (property: string) => { |
||
8 | return (object: any, propertyName: string) => { |
||
9 | const options: ValidationOptions = { |
||
10 | message: `${propertyName} should be greater or equal than ${property}` |
||
11 | }; |
||
12 | registerDecorator({ |
||
13 | name: 'dateGreaterOrEqualThan', |
||
14 | target: object.constructor, |
||
15 | propertyName, |
||
16 | constraints: [property], |
||
17 | options, |
||
18 | validator: { |
||
19 | validate(value: any, args: ValidationArguments) { |
||
20 | const [relatedPropertyName] = args.constraints; |
||
21 | const relatedValue = (args.object as any)[relatedPropertyName]; |
||
22 | |||
23 | return new Date(value) >= new Date(relatedValue); |
||
24 | } |
||
25 | } |
||
26 | }); |
||
27 | }; |
||
28 | }; |
||
29 |