-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
| Item | Version |
|---|---|
| generator-angular-fullstack | 3.10.8 |
| Node | 4.4.7 |
| npm | 3.10.8 |
| Operating System | Fedora 22 |
| Item | Answer |
|---|---|
| Transpiler | Babel |
| Markup | HTML |
| CSS | LESS |
| Router | ui-router |
| Client Tests | Mocha |
| DB | MongoDB |
| Auth | Y |
After initializing the app with yo angular-fullstack
Find any inexisting id for a thing. e.g: 57f016222b63c46b76bf9980
So
GET localhost:3000/api/things/57f016222b63c46b76bf9980
returns 404 not found!
When trying to put an thing with this ID:
e.g:
PUT localhost:3000/api/things/57f016222b63c46b76bf9980
body: {"name": "hello"}
The item is created on the database but HTML get no response at all (browser waiting forever...)
To fix I added a handleEntityNotFound on the file:server/api/thing/thing.controller.js (line 100) on the upsert method
export function upsert(req, res) {
if(req.body._id) {
delete req.body._id;
}
return VizField.findOneAndUpdate({_id: req.params.id}, req.body, {upsert: false, setDefaultsOnInsert: true, runValidators: true}).exec()
.then(handleEntityNotFound(res)) // <-- NEW CODE HERE
.then(respondWithResult(res))
.catch(handleError(res));
}
But as the PUT method returns the old instance, I get a 404 response with this approach which is ugly and may let the client confused.
To get the newly created instance you must pass the option {new: true} as param on the findByIdAndUpdate method.
But this way the integration spec is broken because it expects the OLD instance after PUT and not the newly UPDATED instance
Reactions are currently unavailable