Open rufogongora opened 8 years ago
The HTTP PATCH follows the specs for the HTTP PATCH method: https://tools.ietf.org/html/rfc5789, https://tools.ietf.org/html/rfc6902.
"I'm using an AngularJS $resource PUT request, for example my resource would look like this: return $resource('/api/thing/:id', {id: '@_id'},{ 'update' : {method:'PATCH'} })
" - that's not a PUT, you're manually telling it to use PATCH here..
Here's a simple article about HTTP PATCH: http://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/
@Awk34 Sorry about the confusion on the $resource declaration, I was switching back and forth from update to patch to test what was the issue.
Well my conventional method with the generator's version before 4.0.0 was to simply modify a value of an angular resource (after getting it) then simply call the $update method as declared on the first comment (with a PUT verb instead).
When I tried this on the newest version, some of my other values in the db were being updated for no reason, replacing their values with some of the values of the resource I was trying to update. Then I noticed on the server controller, the PUT verb is actually doing an upsert, which I didn't want, since I was just trying to modify a simple value, that's why I moved to PATCH, however patching was not updating anything on the DB and simply returning a 200.
I assumed the error was with jsonpatch, I moved to lodash and this solved my issue.
I also had the problem with the put. Here is how I resolved it. In the upsert method...
return Link.findOneAndUpdate({_id: req.params.id}, ...
I just generated an endpoint with the generator and I'm getting some weird functionality on it, doing a PATCH request won't work at all and PUT does some weird stuff like it updates some field of other models.
I'm using an AngularJS $resource PUT request, for example my resource would look like this:
return $resource('/api/thing/:id', {id: '@_id'},{ 'update' : {method:'PATCH'} })
After that on the controller I would do:
this.thing.$update((data)=>{console.log(data)})
What I ended up doing was that I went back to the lodash approach instead of jsonpatch and it worked for me.
Instead of using the jsonPatch "PatchUpdates" function I'm using this one
While this is working I'm wondering if the issue is with jsonpatch itself or otherwise, because I'm using the out of the box upsert function and it messes my other data, or is my understanding of upserting wrong?