I have TypeScript NestJS project.
I need to validate incoming DTO to my API. It can be described as "creating of project" where we have type of building (House, Flat, Garden) and depending on that type we need to define:
- House: FLOORS including ROOMS
- Flat: ROOMS
- Garden: nothing (it is one "room")
Example of house type:
{
type: HOUSE,
floors: [
{
name: "1st floor",
rooms: [
{
name: "bedroom"
}
]
}
]
}
Example of flat type:
{
type: FLAT,
rooms: [
{
name: "bedroom"
}
]
}
I've done this in past with help of AJV
, but now as we migrated to NestJS, we started using class-validator
.
My question is, if I can make those advanced conditionals (eg. when type is FLAT, then expect ROOMS only, but not FLOORS) in class-validator
?