Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Parse.Cloud.job("mcItemCount", function(request, response) {
  2.  
  3. // Query all users
  4. var usersQuery = new Parse.Query(Parse.User);
  5.  
  6. // For each user in the DB...
  7. return usersQuery.each(function(user) {
  8.  
  9. //Query all matchCenterItems associated with them
  10. var matchCenterItem = Parse.Object.extend("matchCenterItem");
  11. var mcItemQuery = new Parse.Query(matchCenterItem);
  12. mcItemQuery.equalTo('parent', user);
  13.  
  14. // Set the numberOfItems property equal to the # of matchCenterItems they have
  15. mcItemQuery.find().then(function(results) {
  16. var numberOfItems = results.length;
  17. user.set("numberOfItems", numberOfItems);
  18. });
  19.  
  20. }.then(function() {
  21. // Set the job's success status
  22. response.success("mcItemsCount completed successfully.");
  23. status.success("mcItemsCount completed successfully.");
  24. }, function(error) {
  25. // Set the job's error status
  26. response.error('DAMN IT MAN');
  27. status.error("mcItemsCount FAAAAIIILLED");
  28. });
  29.  
  30. });
  31.  
  32. Parse.Cloud.job("mcItemCount", function(request, status) {
  33. // Query all users
  34. var usersQuery = new Parse.Query(Parse.User);
  35.  
  36. // For each user in the DB...
  37. return usersQuery.each(function(user) {
  38. // ...
  39. }.then(function() {
  40. // Set the job's success status
  41. status.success("mcItemsCount completed successfully.");
  42. }, function(error) {
  43. // Set the job's error status
  44. status.error("mcItemsCount FAAAAIIILLED");
  45. });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement