Conversation
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This is a really useful feature, thanks @gustavohenke for contributing. Hope this gets merged soon so we can remove our custom validators :) |
|
Very neat! Thanks for working on this @gustavohenke! Awesome job 🥇. Does anybody know when it will be merged? |
|
Any estimate on a merge and a release soon please? |
|
Can this solve the issue where I've a single schema to check for both an object in the body and an array of objects in the body by using wildcards? e.g. /* eslint-disable no-param-reassign */
import _ from 'lodash';
/**
* Convert a normal schema to an array schema for express-validator schema object
*
* @param {Object} schema Express Validator Schema
*/
export const convertToArraySchema = schema => _.transform(
schema,
(result, value, key) => {
if (/\bbody\b/.test(`${value.in}`)) {
result[`*.${key}`] = value;
} else {
result[key] = value;
}
},
{},
);
export default convertToArraySchema;EDIT: This works for me 😸 const parentObject = Array.isArray(req[location])
? _.get(req[location], path.replace(/\.?[^.]+$/, ''))
: req[location];
const { eventTypes } = parentObject;^^ this works for both body being an object and an array of object. |
|
pinging again |
|
Please merge this 😄 |
6da0542 to
35b3c41
Compare
|
Hello all. The new proposal looks like this: body('oldPassword')
// if the new password is provided...
.if((value, { req }) => req.body.newPassword)
// OR
.if(body('newPassword').exists())
// ...then the old password must be too...
.not().empty()
// ...and they must not be equal.
.custom((value, { req }) => value !== req.body.newPassword)This might not be as powerful as the old one for now. |
|
Glad to see there’s been work on this, I ended up using the validator library directly and writing the logic with if statements manually for each request. Are there any reasons to use this library instead?
… On Jun 25, 2019, at 5:17 AM, Gustavo Henke ***@***.***> wrote:
Hello all.
This has been refactored now that version 6 is out.
The new proposal looks like this:
body('oldPassword')
// if the new password is provided...
.if((value, { req }) => req.body.newPassword)
// ...then the old password must be too...
.not().empty()
// ...and they must not be equal.
.custom((value, { req }) => value !== req.body.newPassword)
This might not be as powerful as the old one for now, as all you can do is pass a custom validator-like function.
It is however nicer, and closer to what I'd like for express-validator's future.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Hi @Hum4n01d! You can surely achieve all of this on your own, but you will come across code that you have to maintain and test. And one core thing to express-validator that most users don't realise: |
|
👋 this has been published to |
|
I do not think the code works as documented, at least on 6.1.1 works. But would raise exception on |
|
Hey @gwh-cpnet! What values are you testing this validator with? |
|
I think it is |
|
okay. Here is my above would raise exception, if driver === sqlite. but this one works as expected. As you can see, what I need is |
|
@gustavohenke I have made a mocha test script for my point. checkout it out: #762 |
|
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. |
Closes #439.
OLD suggested API
API looks like this at the moment:oneOf()as conditionNEW suggested API looks like this: