如果empty.here是我的格式,我想验证alcoholeId和alcoholeName:
{
"barId": "string",
"barName": "string",
"drinksItems": [
{
"alcoholId": "string",
"alcoholName": "string",
"mixerList": [
{
"mixerId": "string"
}
],
"modifierList": [
{
"modifierId": "string"
}
]
}]
}发布于 2020-04-08 13:37:05
为此,你需要有一个实体,并使用@ValidateNested和@Type来正确地转换它(只有在你使用class-transformer的情况下)。
class Alcohol {
@IsNotEmpty()
alcoholId: string;
@IsNotEmpty()
alcoholName: string;
}
class Bar {
@IsNotEmpty() // <- requires the array to be present
@ValidateNested()
// @Type(() => Alcohol) // <- add only if you use class-transformer
alcohols: Array<Alcohol>;
}https://stackoverflow.com/questions/60990379
复制相似问题