-
Notifications
You must be signed in to change notification settings - Fork 845
Open
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.
Description
I have used a DTO that has a 'property' of type another DTO. In the DTO of the 'property', I want to perform some validations based upon a property in the root DTO. Below mentioned is an example:
I have two DTOs, AnimalDto and AnimalFoodDto:
export enum PetAnimalsType {
Cat = 'cat',
Dog = 'dog',
}
class AnimalDto {
@Apiproperty({enum: PetAnimalsType})
type: PetAnimalsType
@Apiproperty({type: AnimalFood})
food: AnimalFood
}
class AnimalFoodDto {
@ApiProperty()
@Type(({ object }) => {
// _In here how do I get the property 'type' of AnimalDto and use it here in AnimalFoodDto_
const type = object.type;
switch (type) {
case PetAnimalsType.Dog:
return DogStarters;
case PetAnimalsType.Cat:
return CatStarters;
default:
throw new BadRequestException('Invalid Type');
}
})
starters: CatStarters | DogStarters
}
The problem:
How do I access property of a base DTO and do some validations based on that in a DTO of another property of a base DTO
Reference:
The closest Issue that I found was:
#2409
But this is for a property in root. Mine is in a previous layer.
Metadata
Metadata
Assignees
Labels
type: questionQuestions about the usage of the library.Questions about the usage of the library.