feathers-plus / generator-feathers-plus

A Yeoman generator to (re)generate a FeathersJS application supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
44 stars 30 forks source link

fix mismatch on validation code #259

Closed carlosapgomes closed 4 years ago

carlosapgomes commented 5 years ago

Summary

Hi, I am not completely sure about this, but I think that the generated src/services/servicename/servicename.validate.js should have a quickValidate function that looks like this:

let quickValidate = (method, data, options) => {
  try {
    if (method === 'create') { validateCreate(options)({ type: 'before', method: 'create', data }); }
    if (method === 'update') { validateUpdate(options)({ type: 'before', method: 'update', data }); }
    if (method === 'patch') { validatePatch(options)({ type: 'before', method: 'patch', data }); }
  } catch (err) {
    return err;
  }
};

but the generator always create something like this:

let quickValidate = (method, data, options) => {
  try {
    if (method === 'create') { validateCreate(options)({ type: 'before', method: 'create', data }); }
    if (method === 'update') { validateCreate(options)({ type: 'before', method: 'update', data }); }
    if (method === 'patch') { validateCreate(options)({ type: 'before', method: 'patch', data }); }
  } catch (err) {
    return err;
  }
};

This way it will always call the validateCreate function no matter what method (create, update or patch) is used.

Are there any open issues that are related to this?

none that I have noticed.

Is this PR dependent on PRs in other repos?

no

Other Information

I ran the following commands:

find . -name '*.[tj]s' | xargs sed -i '' "s|if (method === 'patch') { validateCreate(options)({ type: 'before', method: 'patch'|if (method === 'patch') { validatePatch(options)({ type: 'before', method: 'patch'|g"

find . -name '*.[tj]s' | xargs sed -i '' "s|if (method === 'update') { validateCreate(options)({ type: 'before', method: 'update'|if (method === 'update') { validateUpdate(options)({ type: 'before', method: 'update'|g"

on test/, test-expand/ and examples/. And also edited: docs/get-started/README.md generators/writing/templates/src/services/name/name.validate.ejs