markusbohl / fluent-ts-validator

Fluent Validation in TypeScript
30 stars 8 forks source link

How to validate dependant properties #11

Closed jjavierdguezas closed 5 years ago

jjavierdguezas commented 5 years ago

for example: startDate: Date and endDate: Date both need to be a Date but also startDate < endDate but I can't find anything like: this.validateIfDate((o) => o.startDate).isBefore((o) => o.endDate) The method isBefore needs a Date , so maybe if I access to the current validating object, but I dont know how?

jjavierdguezas commented 5 years ago

Sorry, I figure it out:

this.validateIf((o) => o)
            .fulfills((o) => o.startDate < o.endDate)
            .when((o) => o.startDate != null && o.endDate != null)
            .withFailureMessage('startDate must be before endDate');