Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Parse.Cloud.define('randomMentor', async function (request, response) {
  2. var Mentor = Parse.Object.extend('Mentor');
  3. var countQuery = new Parse.Query(Mentor);
  4. const count = await countQuery.count();
  5. const query = new Parse.Query('Mentor');
  6. const randomInt = Math.floor(Math.random() * count);
  7. query.equalTo('position', randomInt);
  8. query.limit(1); // limit to at most 10 results
  9. const results = await query.find();
  10.  
  11. const Today = Parse.Object.extend('Today');
  12. const today = new Today();
  13. today.set('mentor', results[0]);
  14. today.save()
  15. .then((today) => {
  16. response.success("Today Mentor Created.");
  17. }, (error) => {
  18. response.error(error);
  19. });
  20. response.success("Today Mentor Created.");
  21. });
  22.  
  23. Parse.Cloud.job('pickTodaysMentor', (request) => {
  24. const { params, headers, log, message } = request;
  25. message("I just started");
  26. Parse.Cloud.run('randomMentor', {}, {
  27. success: function (result) {
  28. },
  29. error: function (error) {
  30. }
  31. });
  32. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement