-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Is it possible to set default values on insert? #339
Comments
since you copied me here, I assume you looked at #322 One way is by adding a middleware that rewrites the request adding
Now, to be honest, I'd simply accept whatever comes in the request, and default |
That would be the easiest way to go. In case the backend team want to do it 'atomic' i can still remove I think its impossible to create schemas because this is a |
it's actually possible to add middlewares all sorts of crazy validation, but I don't think that's the purpose of this library. It's a fake REST API server. I used it for some integration tests I'm writing. The code being tested sends requests to the fake API, and the test code will read what was created. |
@jpbochi My usecase is for develpoment, so i dont have to wait for the backend guys to finish the api. You are right, i overthinked the purpose of the library. I will just send whatever information is needed in the http request. If something needed to be modified later on when i migrate to the real backend api, so be it. |
Hello @typicode,
lets says i have a
Todo
entity, which looks like this:By default all newly inserted
Todo
would be un-completed. This is a typical atomic operation that needs to be done on the server. Which means i won't send thiscompleted
value over the wire with aPOST
request.I found the create method which is responsible for pushing the contents of
req.body
to the end of the given collection.Somehow you need to specify a default value, but for that you need a schema.
I wonder how would you solve something like this?
Right now i solve this with a middleware, but it would be awesome to specify default values by design.
cc @jpbochi
The text was updated successfully, but these errors were encountered: