exadel

JavaScript from 4/30/24 Appery.io Webinar

May 1st, 2014
465
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var result = {};
  2. var params = {};
  3. params.criteria = {'Quantity': { "$lt": 10 }};
  4. result.query = Collection.query("<insert_database_id>", "Menu", params);
  5.  
  6. var item;
  7. var new_inventory = [];
  8.  
  9. for (var i=0; i<result.query.length; i++) {
  10.  
  11. item = {}
  12. item ["Food"] = result.query[i].Food;
  13. item ["Quantity"] = result.query[i].Quantity;
  14.  
  15. new_inventory.push(item)
  16. }
  17.  
  18. response.success(new_inventory);
  19.  
  20. if (result.query.length !=0) {
  21.  
  22. var XHRResponse = XHR.send("POST", "<insert_api_url>", {"body": new_inventory});
  23. console.log("Request for new inventory sent");
  24. }
  25. else {
  26. console.log("No order needed");
  27. }
RAW Paste Data