I have been developing a mock up android app and want to write Parse Background job.
My Parse users are customers and I sell
services that customers can subscribe to. The _User
class is for customers and the CustomerSubscriptions
class is for subscriptions.
I'm trying to update all the customers' bills but I can't.
Can some one steer me in the right direction?
Thanks
Parse.Cloud.job("billCustomers", function(request, response) {
Parse.Cloud.useMasterKey();
var query = new Parse.Query(CustomerSubscriptions);
var array = new Array();
//For each registered user
query.find().then(function(results) {
for (var i = 0; i < results.length; ++i) {
var username = results[i].get("username");
array[username] = results[i].get("Price");
}
var query2 = new Parse.Query(Parse.User);
return query2.find();
}).then(function(results) {
for (var i = 0; i < results.length; ++i) {
var username = results[i].get("username");
results[i].set("Bill",array[username]);
results[i].save();
}
}, function(error) {
response.error("Error");
});
});