adonisjs / validator

Schema based validator for AdonisJS
MIT License
116 stars 39 forks source link

validation rules 'afterField' and 'beforeField' doesn't work #95

Closed fnoquiq closed 4 years ago

fnoquiq commented 4 years ago

I believe that the following rules are not working:

I also opened a call on the github discussion. But no answers.

Package version

"@adonisjs/ace": "^6.9.4",
"@adonisjs/core": "5.0.0-preview-rc-1.11",
"@adonisjs/fold": "^6.4.0",
"@adonisjs/lucid": "^8.3.1",

Node.js and npm version

Node: v12.18.2 Npm: 6.14.5

Sample Code (to reproduce the issue)

public schema = schema.create({
  startDate: schema.date({ format: 'yyyy-MM-dd HH:mm:ss', }, [rules.beforeField('endDate')]),
  endDate: schema.date({ format: 'yyyy-MM-dd HH:mm:ss', })
})

BONUS (a sample repo to reproduce the issue)

https://github.com/fnoquiq/adonis-validator-test

Submit this body to http://0.0.0.0:3333:

{
  "startDate": "2222-02-02 02:02:02",
  "endDate": "2020-01-01 01:01:01"
}

Just remembering the rule being used in the validator:

public schema = schema.create({
  startDate:  [rules.beforeField('endDate')]),
  endDate
})
leognmotta commented 4 years ago

I came here to open an issue, currently having the same problem:

validator:

{
  first_invoice_reminder: schema.date.optional({}, [rules.after('today')]),
  last_invoice_reminder: schema.date.optional({}, [
  rules.afterField('first_invoice_reminder'),
  ]),
}

request:

{
  "first_invoice_reminder": "2020-08-15T18:00:25.800-03:00",
  "last_invoice_reminder": "2010-09-15T18:00:25.800-03:00",
}

and it is getting validated.