-
Notifications
You must be signed in to change notification settings - Fork 122
Description
Hello,
when I update an existing model, the returned value does not contain the updated resource from the server, but the same model from before:
// ...
console.log(comment.updatedAt); // '2017-04-06T04:32:46.919Z'
console.log(comment.rating); // '3'
comment.rating = 5;
comment.save().subscribe(updatedComment => {
console.log(updatedComment.updatedAt === comment.updatedAt); // true but should be false
console.log(updatedComment.rating); // '5'
});My backend changes the updatedAt property of comment and returns the updated resource with the status 200 OK, but the updated comment is not returned by the save method.
The problem came with this commit:
.map((res: any) => this.extractRecordData(res, modelType, model)) // old
.map(res => res.status === 201 ? this.extractRecordData(res, modelType, model) : model) // newSince then, only data from 201 Created responses gets extracted. But as described in http://jsonapi.org/format/#crud-updating-responses, a PATCH request can respond with 200 OK or 204 No Content (and 202 Accepted).
So if the server responds with 200 OK we also should call this.extractRecordData(res, modelType, model) to update the model with the updates from the server. Further it is possible that the 200 OK does only contain meta information but no updated resource (data). This should be handled in the extractRecordData method as well.
I will create a pull request to resolve this issue. Does anyone has some other suggestions how to solve this problem?
Cheers