我没有很多使用Nodejs/Nestjs进行开发的经验。我正在开发一个REST API,其中一个端点接收具有生日属性的用户主体。
我想确认出生日期总是在当天之前。这是我的代码片段:
import { IsString, IsDateString, MaxDate } from 'class-validator';
export class CreateUserDto {
@IsString()
readonly username: string;
@IsDateString()
@MaxDate(new Date())
readonly dateofbirth: Date;
}这是我的实体:
import { Entity, Column, PrimaryColumn } from 'typeorm';
@Entity()
export class User {
@PrimaryColumn()
username: string;
@Column()
dateofbirth: Date;
}然而,当发出POST请求时,我总是得到相同的错误,并且不能理解为什么:{"statusCode":400,"message":["maximal allowed date for dateofbirth is Mon Nov 01 2021 12:20:11 GMT+0000 (Western European Standard Time)"],"error":"Bad Request"}
感谢您的帮助和时间。
发布于 2021-11-01 17:00:11
我解决了从class-transformer向出生日期添加@Type(() => Date)时的问题
https://stackoverflow.com/questions/69798969
复制相似问题