odatajaydata

JayData - Read response from HTTP Patch


I am trying to apply some changes to my client side JavaSript objects from an ODataController based service after making a PATCH call using JayData. How do I view the HTTP response (200) after making a PATCH request? I don't see where the JayData API exposes the response. My code looks something like this:

var deferred = $q.defer();
self.context.ready.then(function (cxt) {
    myAwesomeEntity.entityState = $data.EntityState.Modified;
    cxt.myAwesomeEntitys.attach(myAwesomeEntity, true);

    // HACK update the TimeStamp reference to trick JayData into including it in the HTTP PATCH request.
    var temp = myAwesomeEntity.Timestamp;
    myAwesomeEntity.Timestamp = [];
    myAwesomeEntity.Timestamp = temp;

    cxt.saveChanges().then(function (data) {
        deferred.resolve(data); // Shouldn't data be the HTTP Patch response?  It's actually "3".
    }, function (error) {
        //Handle error here...
    });
});

return deferred.promise;

The HTTP Patch (200) response looks something like:

{
    "odata.metadata": "http://localhost:21171/odata/$metadata#MyAwesomeEntity/@Element",
    "odata.type": "MyNamespace.MyAwesomeEntity",
    "odata.id": "http://localhost:21171/odata/MyAwesomeEntity(guid'14812a96-8da1-4202-b8c7-a5697774ae4b')",
    "SomeCollection@odata.navigationLinkUrl": "http://localhost:21171/odata/MyAwesomeEntity(guid'14812a96-8da1-4202-b8c7-a5697774ae4b')/SomeCollection",
    "Timestamp@odata.type": "Edm.Binary",
    "Timestamp": "AAAAAAJxWhg="
}

Solution

  • The JayData oDataProvider returns the count of the number of items affected. I modified it to return the actual items modified.