1 | const _ = require('lodash');
|
2 | const selectFields = require('../check/select-fields');
|
3 |
|
4 | module.exports = (req, { onlyValidData = true } = {}) => {
|
5 | const validityFilter = !onlyValidData ? () => true : field => {
|
6 | return !req._validationErrors.find(error =>
|
7 | error.param === field.path &&
|
8 | error.location === field.location
|
9 | );
|
10 | };
|
11 |
|
12 | return _(req._validationContexts)
|
13 | .flatMap(context => selectFields(req, context))
|
14 | .filter(validityFilter)
|
15 | .reduce((state, field) => _.set(state, field.path, field.value), {})
|
16 | .valueOf();
|
17 | }; |
\ | No newline at end of file |