persist-values.js 411 B

123456789101112
  1. const _ = require('lodash');
  2. module.exports = (req, fieldInstances) => {
  3. fieldInstances.filter(instance => {
  4. const initialValue = _.get(req[instance.location], instance.path);
  5. return initialValue !== instance.value;
  6. }).forEach(instance => {
  7. instance.path === ''
  8. ? _.set(req, instance.location, instance.value)
  9. : _.set(req[instance.location], instance.path, instance.value);
  10. });
  11. };