Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. /**
  2. * CheckOut timer.
  3. * It is executed according to the schedule
  4. */
  5. Backendless.ServerCode.addTimer({
  6.  
  7. name: 'CheckOut',
  8.  
  9. startDate: 1504501863000,
  10.  
  11. frequency: {
  12. schedule: 'daily',
  13.  
  14. repeat: {'every':1}
  15. },
  16.  
  17.  
  18. /**
  19. * @param {Object} req
  20. * @param {String} req.context Application Version Id
  21. */
  22. execute(req){
  23. Backendless.Data.of("Bookings").find()
  24. .then(function (result){
  25. var res = result;
  26. })
  27. .catch(function (error){
  28. });
  29. for (var i=0; i<res.length; i++) {
  30. var today = new Date();
  31. var out = new Date(res[i].checkout);
  32. if (out.getDate() == today.getDate() && out.getMonth() == today.getMonth() && out.getFullYear() == today.getFullYear() && res[i].in_use == true) {
  33. res[i].in_use = false;
  34. var hId = res[i].hotelID;
  35. Backendless.Data.of("Hotels").save({objectId: hId, free_rooms: free_rooms + res[i].rooms})
  36. .then(function(res) {
  37. })
  38. .catch(function(error) {
  39.  
  40. });
  41. }
  42. }
  43. }
  44. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement