Running this code in my Parse cloud, I noticed that when I call it from my app, it never enters the success or error statement. Could it be because the .save method isn't working?
Any assistance would be greatly appreciated :)
This is how I invoke the cloud function:
[PFCloud callFunctionInBackground:@"addFeeling"
withParameters:@{@"userId" : [[PFUser currentUser]objectId],
@"relationShipId" : _friendship.objectId,
@"tagId" : [NSNumber numberWithInt:tag],
@"reason" : @"Hardcoded HomeView(409)",
@"value" : [NSNumber numberWithInt:value]}
block:^(NSString *result, NSError *error) {
if (!error) {
DLog(@"results :%@", result);
}
else{
DLog(@"Error : %@", error);
}
}];
And here's the cloud function itself:
Parse.Cloud.define("addFeeling", function(request, response) {
var userId = request.params.userId;
var relationShipId = request.params.friendshipId;
var tagId = request.params.tagId;
var reason = request.params.reason;
var value = request.params.value;
var Feels = Parse.Object.extend("Feels");
var feeling = new Feels();
feeling.set("id_friendship", relationShipId);
feeling.set("value", value);
feeling.set("tag", tagId);
feeling.set("reason", reason);
feeling.save({
success: function () {
var query = new Parse.Query("Feels");
query.equalTo("id_friendship", relationShipId);
query.find({
success: function(results) {
if(results.length > 0)
{
result = results[0];
if(result.get("userFrom") == userId)
result.set("scoreTo" , result.get("scoreTo") + value);
else
result.set("scoreFrom", result.get("scoreFrom") + value);
result.save();
}
}
});
console.log("Save ok");
},
error: function (error) {
response.error(error);
console.log("Save ko");
}
});
});
This might seem really simple, but I'm just not familiar with JavaScript at all.
The error code I'm receiving is 141, and it never enters the success/error statements.