typestack / class-validator

Decorator-based property validation for classes.
MIT License
10.92k stars 787 forks source link

Performing sequential and asynchronous custom validation #2528

Open PerceptControl opened 3 weeks ago

PerceptControl commented 3 weeks ago

I stuck in situation where I need to do serial db queries on validation stage. For example:

{
   Validate(aExistInDb)
   fieldA: string

   Validate(bExistInDb)
   fieldB: string
}

Let's assume validators "aExistInDb" and "bExistInDb" both are async and execute some select queries from db

In my situation field b relates on a. It means that I want to check fieldB only when I sure that "a" field exist and correct. I expected that "bExistInDb" validation will run only when "aExistInDb" ends. But now both starts immediately.

What shall I do then?