(optional) null should be part of matchedData
See original GitHub issueHi,
TLDR: matchedData()
is not returning my body field with JSON value of null
, while I try to validate the data with the check API.
I don’t know if I use your validator incorrect or if it’s a feature request… but… I use your validator for my backend app before sending the JSON object further to the database (eg. MariaDB).
I have a database field what either can be of type integer or have the value of NULL
. So I tried to use your validator in this way (at least this is what I thought should work):
body('journal_bank_id').optional({nullable: true}).isInt()
However, I’m also using the filter matchedData()
function in order to guarantee that my data I put in my database is fully validated first by your validator package 👍
object = matchedData(req)
Now, when I try to request an API call to the Express backend using your validator with the HTTP body:
{"journal_bank_id": null}
Expected situation: I would expect the JSON object is now validated correctly and the journal_bank_id with null value becomes part of the returned object from matchedData()
. Meaning the MySQL query will set the corresponding field to NULL accordantly. So basically I would expect matchedData()
returns:
{"journal_bank_id": null}
Actual situation: matchedData()
is not returning journal_bank_id
with value null
at all. Meaning my database field can’t be set to NULL because of your validator.
Do I miss something here? Should I maybe not use optional()? I couldn’t find isNull()
… I have no clue anymore…
Thanks in advance!
Kind regards, Melroy van den Berg
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (5 by maintainers)
Top GitHub Comments
Shipped on v5.3.0! 🚢
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.