Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Router: validate against _partial_ model interface #1443

Closed
joeytwiddle opened this issue Jun 20, 2018 · 1 comment
Closed

Router: validate against _partial_ model interface #1443

joeytwiddle opened this issue Jun 20, 2018 · 1 comment

Comments

@joeytwiddle
Copy link
Contributor

joeytwiddle commented Jun 20, 2018

I wanted to make a comment on #118 but it's probably neater to make a separate issue.

There is a use case which we use quite often. That is:

  • The user POSTs some data to create a new document, but they don't pass all the data.
  • Some of the fields are added by our controller, not the user.

In this case, we would like to validate the user's input against a partial interface of the model, not the complete model interface.

Example:
We have a database of recipes that look like:

{
  name: 'Carrot cake',
  author: 'user-1234',
  instructions: '...' ,
  creationDate: '12/4/2057',
}

When the users posts a new recipe, we don't want or expect them to pass the creationDate or the author, because those will be added by the system.

How will will be able to tell the route-level validator which of the user-supplied fields we do or (preferably) don't want to validate?

Could we perhaps extend the Recipe interface, delete a few fields, and pass that to the validator?


Additional: There are also sometimes cases where the user will send more fields than are in the collection.

(For example, during signup, they often provide a 'password' field, but our controller removes that before saving the document, preferring to hash it and store it in a separate collection.)

So in general, this issue is about modifying the interface, with addition or removal, before using it for validation.


EDIT: Thanks shimks, 1179 does indeed cover this use case. No need for me to keep this open.

@shimks
Copy link
Contributor

shimks commented Jun 20, 2018

Hi @joeytwiddle, I believe the feature request you're proposing is tracked by #1179. Please take a look at the issue and let us know if it covers what you'd like to see with partial model validation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants