我收到错误,PartialType 不适用于 updateDto

问题描述 投票:0回答:1

partialType 不适用于我的 updateDto 它没有在 updateDto 中选择我的嵌套对象变量。最主要的是它唯一不适用于布尔值意味着不在 updateDto 中执行选项布尔类型 这是createDto


class PoolDTO {
  @IsBoolean()
  present: boolean;

  @IsOptional()
  @IsString()
  fence: string;

  @IsOptional()
  @IsString({ each: true })
  location: string;
}
class UtilitiesDTO {
  @IsBoolean()
  sprinklerSystem: boolean;

  @IsBoolean()
  sumpPump: boolean;

  @IsBoolean()
  sumpPit: boolean;

  @ValidateNested()
  @Type(() => PoolDTO)
  pool: PoolDTO;

  @IsBoolean()
  spaHot: boolean;

  @IsBoolean()
  water: boolean;

  @IsBoolean()
  gas: boolean;

  @IsBoolean()
  electric: boolean;

  @IsOptional()
  @IsString()
  comment: string;
}
export class CreateDto{
   @IsString()
   @IsNotEmpty()  
   number: string;
 
    @ValidateNested()
    @Type(() => PoolDTO)
    pool: PoolDTO;

    @ValidateNested({ each: true })
    @Type(() => UtilitiesDTO)  
    utilities: UtilitiesDTO; 

这是更新 dto

import { PartialType } from '@nestjs/mapped-types';
import { CreateDto } from './create.dto';


export class UpdateDto extends PartialType(CreateDto) {}

它给了我验证错误

 "messages": [
        "utilities.sprinklerSystem must be a boolean value",
        "utilities.sumpPump must be a boolean value",
        "utilities.sumpPit must be a boolean value",
        "utilities.water must be a boolean value",
        "utilities.gas must be a boolean value",
        "utilities.electric must be a boolean value"
    ]

但我用的是 PartialType PartialType() 函数返回一个类型(类),其中输入类型的所有属性都设置为可选。 我仍然收到错误,我不想写updatedto,想使用相同的createdto来更新updatedto

javascript node.js typescript nestjs typeorm
1个回答
0
投票

PartialType() 函数是从 @nestjs/swagger 包导入的。

import { PartialType } from '@nestjs/swagger';

export class UpdateCatDto extends PartialType(CreateCatDto) {}

© www.soinside.com 2019 - 2024. All rights reserved.