Maybe I don't understand the DTO, but I want it to check if at least one attribute is sent by the request. How can I do it?
Here is my dto:
//import libs
export class WorkspaceDto {
@IsString()
@IsNotEmpty()
@Transform(({ value }) => value?.trim())
@ApiProperty()
@IsOptional()
id?: string;
@IsString()
@IsNotEmpty()
@Transform(({ value }) => value?.trim())
@ApiProperty()
@IsOptional()
name?: string;
@IsNotEmpty()
@IsString()
@Transform(({ value }) => value?.trim())
@ApiProperty()
@IsOptional()
domain?: string;
@IsNotEmpty()
@IsString()
@Transform(({ value }) => value?.trim())
@IsOptional()
@ApiProperty({ enum: WorkspaceStatusEnum, required: false })
@IsEnum(WorkspaceStatusEnum)
status?: WorkspaceStatusEnum;
}
For example, if an user sent {}, will it accept and return everything?(which we don't expect). Any way to prevent it?
You can create a custom validation pipe like below:
Then, you can use it like this in your controller