Feature/improve date validation in activity endpoints (#3489)
* Improve date validation * Update changelogpull/3491/head
parent
0adefe14e1
commit
bf20a5de82
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"meta": {
|
||||||
|
"date": "2021-01-01T00:00:00.000Z",
|
||||||
|
"version": "dev"
|
||||||
|
},
|
||||||
|
"activities": [
|
||||||
|
{
|
||||||
|
"currency": "USD",
|
||||||
|
"dataSource": "YAHOO",
|
||||||
|
"date": "1960-01-01T00:00:00.000Z",
|
||||||
|
"fee": 0,
|
||||||
|
"quantity": 20,
|
||||||
|
"symbol": "AAPL",
|
||||||
|
"type": "BUY",
|
||||||
|
"unitPrice": 100.0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in new issue