adonisjs / validator

Schema based validator for AdonisJS
MIT License
115 stars 40 forks source link

feat: Add beforeOrEqual & afterOrEqual validators #132

Closed Vong3432 closed 2 years ago

Vong3432 commented 2 years ago

Proposed changes

Added beforeOrEqual & afterOrEqual validators to handle scenario where a given date from the request body need to be after/before or equal to today to be valid. Discussion thread

Types of changes

What types of changes does your code introduce?

Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

I took the test cases from after.spec.ts and before.spec.ts and added new logic to test cases to check beforeOrEqual/afterOrEqual validators.

thetutlage commented 2 years ago

The tests are failing. Can you please look into it?

Vong3432 commented 2 years ago

The tests are failing. Can you please look into it?

I think previously the test work fine when time is after or equal to the defined interval fails because the tested DateTime is executed first (which may have milliseconds: 300) , and the DateTime that produced afterward during the validation in the "Validations/date/helpers/offset.ts" files would have milliseconds: 500, thus making the tested DateTime would always lesser than the DateTime that use compile(30, "minutes").

So I have done some modification in that test case by adding a max milliseconds and seconds in the tested DateTime to force them compare minutes only.

thetutlage commented 2 years ago

Thanks for the PR :)