Description
Hi,
I have several Cloud Code functions that I call using the Rest API, and that update some objects. At the end of the functions, the modified object is returned by using response.success(). When I call the same functions with parse-server, the response is different.
This is an example to reproduce it.
Create a beforeSave trigger and a Cloud Code function like this:
/**
* @description Sets the value of the field "auto" on each new book
*/
Parse.Cloud.beforeSave("Book", function(request, response) {
if (request.object.isNew()) {
var title = request.object.get("title");
request.object.set("auto", title + "-auto");
}
response.success();
});
/**
* @description A minimalist function that creates a new book and saves it
*/
Parse.Cloud.define("createBook", function(request, response) {
var testObject = new Parse.Object("Book");
testObject.set("title", "The Old Man and the Sea");
testObject.save().then(function(result) {
console.log(result); // we log the object returned by save()
response.success(result);
}).fail(function(err) {
response.error(err);
});
});
If the code is deployed on Parse.com, and you call the function "createBook" using the REST API, the new "Book" object is returned by response.success(). The line with console.log() displays the object returned by save():
{"title":"The Old Man and the Sea","auto":"The Old Man and the Sea-auto","objectId":"KTnRfSw3QW","createdAt":"2016-02-25T13:24:57.124Z","updatedAt":"2016-02-25T13:24:57.124Z"}
If you use parse-server locally, the result of the save() operation is different, and the object returned by response.success() is different too (the "auto" field is missing). The line with console.log() displays the object returned by save() on parse-server:
ParseObject { _objCount: 0, className: 'Book', id: 'XiDFZ3dczo' }
So, all my code that returns the result of the save() operation into response.success() does not work anymore.
Thanks.