Reputation: 9295
I am using parse.com as my backend.
I have made the below cloud code, and it's giving me {u'code': 141, u'error': u'success/error was not called'}
code. I know that I am not making the response.success call after the first success but I am doing it in the chained function called nextSaleRate.
Is there any way to work it out?
Here is the full code:
function SaleWithRate(){
saleId = undefined;
rating = 0.0;
}
function nextSaleRate(saleList, nextSale, arr, response){
if(nextSale < saleList.length) {
var sale = new SaleWithRate();
sale.saleId = saleList[nextSale].id;
//creating ShaleSale object for Rates query
var ShaleSale = Parse.Object.extend("ShaleSale");
var saleForRate = new ShaleSale();
saleForRate.id = sale.saleId;
//query
var rateQuery = new Parse.Query("ShaleSaleRate");
rateQuery.equalTo("saleId", saleForRate);
rateQuery.find({
success: function(rateList) {
var sum = 0;
var index = 0;
for(var j = 0; j < rateList.length; j++) {
index++;
sum += rateList[j].get("rate");
if(index === 0) {
sale.rating = 0;
}
else {
sale.rating = sum/index;
}
arr.push(sale);
nextSale++;
nextSaleRate(saleList, nextSale, arr, response);
}
},
error: function() {
response.error("rate lookup failed");
}
});
}
else {
console.log("when do I get in" + nextSale);
response.success(arr);
}
}
Parse.Cloud.define("getSalesWithRate", function(request, response){
var query = new Parse.Query("ShaleSale");
query.ascending("createdAt");
//query.notContainedIn("objectId", request.params.saleIds);
query.find({
success: function(results) {
var arr = new Array();
nextSaleRate(results, 0, arr, response);
},
error: function() {
response.error("sale lookup failed");
}
});
});
Upvotes: 0
Views: 1169
Reputation: 9258
The error message is actually referring to the fact that response.success() is not being called from your Cloud Function. You're not passing the response object to your next Sale Rate function.
Upvotes: 1