0

如果它为空,我想验证酒精 ID 和酒精名称。这是我的格式:

   {
     "barId": "string",
     "barName": "string",
     "drinksItems": [
      {
      "alcoholId": "string",
      "alcoholName": "string",
      "mixerList": [
         {
           "mixerId": "string"
         }
       ],
      "modifierList": [
         {
           "modifierId": "string"
         }
       ]
    }]
}
4

1 回答 1

0

为此,您需要拥有一个实体并正确使用@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>;
}
于 2020-04-08T05:37:05.437 回答