Closed rafal-rudnicki closed 6 years ago
Use @IsDateString()
instead (see here https://github.com/typestack/class-validator)
You can use @Type
decorator from class-transformer
(docs)
Like this:
import { Type } from 'class-transformer';
export class ExampleDto {
@IsDate()
@Type(() => Date)
someDate: Date
}
My controllers receive the properties as Date
objects when the request was sent with ISO String
Just in case you're wondering, I'm applying the ValidationPipe
like this:
import { ValidationPipe } from '@nestjs/common';
async function bootstrap() {
// ...
app.useGlobalPipes(new ValidationPipe({ forbidUnknownValues: true }));
// ...
}
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I'm submitting a...
I'm wondering how to send date by POST method and validate that by @IsDate() decorator from class-validator library. I'm trying to achieve that by DTO class which looks this way:
but as a result i can't send date which has that format: "2018-05-23T18:25:43.511Z", because i have that error: "availableFrom must be a Date instance". Could someone send me an example how to do it right way? Thx!