{"action":"created","comment":{"url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/comments/182125839","pull_request_review_id":112874478,"id":182125839,"diff_hunk":"@@ -1499,6 +1499,180 @@ app.delete(\"/room/:roomId\", function (req, res) {\n     });\n });\n \n+\n+//suggest meeting times given list of participants\n+app.post(\"/api/meetingSuggestion\", function (req, res) {\n+\n+    //currently only look 3 days ahead, and assume 7AM - 5PM workday. only search on weekdays\n+\n+    if(!req.body.participants) {\n+      res.statusCode = 400;\n+      console.log();\n+      res.json({\n+        \"requestURL\":  \"/room\",\n+        \"action\": \"post\",\n+        \"status\": 400,\n+        \"message\": \"Bad Request\",\n+        \"timestamp\": new Date()\n+      });\n+    }\n+\n+    else {\n+\n+      var participants = req.body.participants || null;\n+\n+      //using ADDDATE(CURDATE(), 4) just to limit the amount of meetings to search through later\n+      var getMeetingSql = \"SELECT DISTINCT(start_datetime), end_datetime FROM ebdb.meeting WHERE start_datetime >= CURDATE() AND end_datetime < ADDDATE(CURDATE(), 4) AND \"\n+                         + \"calendar IN (SELECT primary_calendar FROM ebdb.user WHERE email IN (?)) ORDER BY end_datetime;\";\n+      var inserts = [participants];\n+\n+      pool.query(getMeetingSql, inserts, function(error, results, fields) {\n+        if(error) {\n+          res.statusCode = 500;\n+          console.log(error);\n+          res.json({\n+            \"requestURL\":  \"/meetingSuggestion\",\n+            \"action\": \"post\",\n+            \"status\": 500,\n+            \"message\": \"Query failed for calendar\",\n+            \"timestamp\": new Date()\n+          });\n+        }\n+        else {\n+          \n+          var meetings = results;\n+\n+          var parameters = {\n+            meetings: meetings,\n+            numDaysAhead: req.body.numDaysAhead,\n+            startTime: req.body.startTime,\n+            endTime: req.body.endTime\n+          };\n+\n+          var timetable = createTimetable(parameters);\n+\n+          var countTimes = 0;\n+          var suggestions = [];\n+          //iterate through timetable and find first 5 suggestions\n+          for(var time in timetable) {\n+            if(countTimes == 5) {\n+              break;\n+            }\n+            if(timetable[time] == 0) {\n+              countTimes++;\n+              suggestions.push(time);\n+            }\n+          }\n+          //console.log(timetable);\n+          //console.log(suggestions);\n+          res.send([meetings, timetable, suggestions]);\n+\n+        }\n+      });\n+\n+    }\n+\n+});\n+\n+function createTimetable(parameters) {\n+\n+    var meetings = parameters.meetings || null;\n+    //var workdays = parameters.workdays || [1,2,3,4,5]; //list of workdays in the week (0-6)\n+    var numDaysAhead = parameters.numDaysAhead || 3; //look ahead 3 days\n+    var startTime = parameters.startTime || 7; //default start at 7AM\n+    var endTime = parameters.endTime || 17; //default end at 5PM\n+\n+    //get current date info\n+    var currDate = new Date();\n+    var currHour = currDate.getHours();\n+    var currMin = currDate.getMinutes();\n+\n+    currDate.setSeconds(0);\n+    currDate.setMilliseconds(0);\n+\n+    //round up to the nearest 30 min\n+    if(currMin > 30) {\n+      currMin = 0;\n+      currHour++;\n+      currDate.setHours(currHour);\n+      currDate.setMinutes(currMin);\n+\n+    }\n+    else {\n+      currMin = 30;\n+      currDate.setHours(currHour);\n+      currDate.setMinutes(currMin);\n+    }\n+\n+    //if weekend, or friday after endTime, start searching monday at startTime\n+    if(currDate.getDay() == 6 || currDate.getDay == 0 ||\n+       (currDate.getDay() == 5 && currDate.getHour() >= endTime)) {\n+      if(currDate.getDay() == 6) {\n+        currDate.setDate(currDate.getDate() + 2);\n+      }\n+      else if(currDate.getDay() === 0) {\n+        currDate.setDate(currDate.getDate() + 1);\n+      }\n+      else {\n+        currDate.setDate(currDate.getDate() + 3);\n+      }\n+      currHour = startTime;\n+      currMin = 0;\n+      currDate.setHours(startTime);\n+      currDate.setMinutes(0);\n+    }\n+\n+    var timetable = {};\n+\n+    var workhours = endTime - startTime;\n+    //search for the next 3 days\n+    for(var i = 0; i < workhours*2*numDaysAhead; i++) { //*2 (for half hour intervals) * numDaysAhead to look\n+      //if past endTime, go to startTime the next day\n+      if(currHour >= endTime) {\n+        currHour = startTime;\n+        currMin = 0;\n+        currDate.setHours(currHour);\n+        currDate.setMinutes(currMin);\n+        currDate.setDate(currDate.getDate()+1);\n+      }\n+\n+      timetable[currDate.toUTCString()] = 0;\n+\n+      var x = 0;\n+      //iterate through all meetings. if we find a meeting that conflicts, set that to busy\n+      //if we don't, then the time is open/free\n+      while(x < meetings.length) {\n+        //i thought i'd be able to cut down on the meetings searched through, but this doesn't work???\n+        // if((new Date(meetings[x].end_datetime)).getTime() > (new Date(currDate)).getTime()) {","path":"app.js","position":148,"original_position":148,"commit_id":"f0cc494a047400f3de943c40aac972dd24ba4f1f","original_commit_id":"f0cc494a047400f3de943c40aac972dd24ba4f1f","user":{"login":"mwang25277","id":13982474,"avatar_url":"https://avatars2.githubusercontent.com/u/13982474?v=4","gravatar_id":"","url":"https://api.github.com/users/mwang25277","html_url":"https://github.com/mwang25277","followers_url":"https://api.github.com/users/mwang25277/followers","following_url":"https://api.github.com/users/mwang25277/following{/other_user}","gists_url":"https://api.github.com/users/mwang25277/gists{/gist_id}","starred_url":"https://api.github.com/users/mwang25277/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwang25277/subscriptions","organizations_url":"https://api.github.com/users/mwang25277/orgs","repos_url":"https://api.github.com/users/mwang25277/repos","events_url":"https://api.github.com/users/mwang25277/events{/privacy}","received_events_url":"https://api.github.com/users/mwang25277/received_events","type":"User","site_admin":false},"body":"Here, i thought i could break out of this loop once I reach a point where the meeting date comes after the currDate, but this didn't seem to work","created_at":"2018-04-17T15:46:54Z","updated_at":"2018-04-17T15:46:54Z","html_url":"https://github.com/zednis/meeting-scheduler-api/pull/13#discussion_r182125839","pull_request_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/comments/182125839"},"html":{"href":"https://github.com/zednis/meeting-scheduler-api/pull/13#discussion_r182125839"},"pull_request":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13"}}},"pull_request":{"url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13","id":181709146,"html_url":"https://github.com/zednis/meeting-scheduler-api/pull/13","diff_url":"https://github.com/zednis/meeting-scheduler-api/pull/13.diff","patch_url":"https://github.com/zednis/meeting-scheduler-api/pull/13.patch","issue_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/13","number":13,"state":"open","locked":false,"title":"/api/meetingSuggestion","user":{"login":"mwang25277","id":13982474,"avatar_url":"https://avatars2.githubusercontent.com/u/13982474?v=4","gravatar_id":"","url":"https://api.github.com/users/mwang25277","html_url":"https://github.com/mwang25277","followers_url":"https://api.github.com/users/mwang25277/followers","following_url":"https://api.github.com/users/mwang25277/following{/other_user}","gists_url":"https://api.github.com/users/mwang25277/gists{/gist_id}","starred_url":"https://api.github.com/users/mwang25277/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwang25277/subscriptions","organizations_url":"https://api.github.com/users/mwang25277/orgs","repos_url":"https://api.github.com/users/mwang25277/repos","events_url":"https://api.github.com/users/mwang25277/events{/privacy}","received_events_url":"https://api.github.com/users/mwang25277/received_events","type":"User","site_admin":false},"body":"closes https://github.com/zednis/alexa-skill-meeting-scheduler/issues/34","created_at":"2018-04-15T17:00:42Z","updated_at":"2018-04-17T15:46:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"654d59697b2c6a8e8047aed92b001883dfda041a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13/commits","review_comments_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13/comments","review_comment_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/13/comments","statuses_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/statuses/f0cc494a047400f3de943c40aac972dd24ba4f1f","head":{"label":"zednis:meeting_suggestions_endpoint","ref":"meeting_suggestions_endpoint","sha":"f0cc494a047400f3de943c40aac972dd24ba4f1f","user":{"login":"zednis","id":1057295,"avatar_url":"https://avatars0.githubusercontent.com/u/1057295?v=4","gravatar_id":"","url":"https://api.github.com/users/zednis","html_url":"https://github.com/zednis","followers_url":"https://api.github.com/users/zednis/followers","following_url":"https://api.github.com/users/zednis/following{/other_user}","gists_url":"https://api.github.com/users/zednis/gists{/gist_id}","starred_url":"https://api.github.com/users/zednis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zednis/subscriptions","organizations_url":"https://api.github.com/users/zednis/orgs","repos_url":"https://api.github.com/users/zednis/repos","events_url":"https://api.github.com/users/zednis/events{/privacy}","received_events_url":"https://api.github.com/users/zednis/received_events","type":"User","site_admin":false},"repo":{"id":122763436,"name":"meeting-scheduler-api","full_name":"zednis/meeting-scheduler-api","owner":{"login":"zednis","id":1057295,"avatar_url":"https://avatars0.githubusercontent.com/u/1057295?v=4","gravatar_id":"","url":"https://api.github.com/users/zednis","html_url":"https://github.com/zednis","followers_url":"https://api.github.com/users/zednis/followers","following_url":"https://api.github.com/users/zednis/following{/other_user}","gists_url":"https://api.github.com/users/zednis/gists{/gist_id}","starred_url":"https://api.github.com/users/zednis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zednis/subscriptions","organizations_url":"https://api.github.com/users/zednis/orgs","repos_url":"https://api.github.com/users/zednis/repos","events_url":"https://api.github.com/users/zednis/events{/privacy}","received_events_url":"https://api.github.com/users/zednis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zednis/meeting-scheduler-api","description":null,"fork":false,"url":"https://api.github.com/repos/zednis/meeting-scheduler-api","forks_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/forks","keys_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/teams","hooks_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/hooks","issue_events_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/events{/number}","events_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/events","assignees_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/assignees{/user}","branches_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/branches{/branch}","tags_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/tags","blobs_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/statuses/{sha}","languages_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/languages","stargazers_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/stargazers","contributors_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/contributors","subscribers_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/subscribers","subscription_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/subscription","commits_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/contents/{+path}","compare_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/merges","archive_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/downloads","issues_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues{/number}","pulls_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls{/number}","milestones_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/milestones{/number}","notifications_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/labels{/name}","releases_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/releases{/id}","deployments_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/deployments","created_at":"2018-02-24T17:36:57Z","updated_at":"2018-04-17T03:29:27Z","pushed_at":"2018-04-17T15:44:04Z","git_url":"git://github.com/zednis/meeting-scheduler-api.git","ssh_url":"git@github.com:zednis/meeting-scheduler-api.git","clone_url":"https://github.com/zednis/meeting-scheduler-api.git","svn_url":"https://github.com/zednis/meeting-scheduler-api","homepage":null,"size":652,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"zednis:master","ref":"master","sha":"4d55cb5171b76e92aad8b668eabd2978a34cdd36","user":{"login":"zednis","id":1057295,"avatar_url":"https://avatars0.githubusercontent.com/u/1057295?v=4","gravatar_id":"","url":"https://api.github.com/users/zednis","html_url":"https://github.com/zednis","followers_url":"https://api.github.com/users/zednis/followers","following_url":"https://api.github.com/users/zednis/following{/other_user}","gists_url":"https://api.github.com/users/zednis/gists{/gist_id}","starred_url":"https://api.github.com/users/zednis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zednis/subscriptions","organizations_url":"https://api.github.com/users/zednis/orgs","repos_url":"https://api.github.com/users/zednis/repos","events_url":"https://api.github.com/users/zednis/events{/privacy}","received_events_url":"https://api.github.com/users/zednis/received_events","type":"User","site_admin":false},"repo":{"id":122763436,"name":"meeting-scheduler-api","full_name":"zednis/meeting-scheduler-api","owner":{"login":"zednis","id":1057295,"avatar_url":"https://avatars0.githubusercontent.com/u/1057295?v=4","gravatar_id":"","url":"https://api.github.com/users/zednis","html_url":"https://github.com/zednis","followers_url":"https://api.github.com/users/zednis/followers","following_url":"https://api.github.com/users/zednis/following{/other_user}","gists_url":"https://api.github.com/users/zednis/gists{/gist_id}","starred_url":"https://api.github.com/users/zednis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zednis/subscriptions","organizations_url":"https://api.github.com/users/zednis/orgs","repos_url":"https://api.github.com/users/zednis/repos","events_url":"https://api.github.com/users/zednis/events{/privacy}","received_events_url":"https://api.github.com/users/zednis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zednis/meeting-scheduler-api","description":null,"fork":false,"url":"https://api.github.com/repos/zednis/meeting-scheduler-api","forks_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/forks","keys_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/teams","hooks_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/hooks","issue_events_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/events{/number}","events_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/events","assignees_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/assignees{/user}","branches_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/branches{/branch}","tags_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/tags","blobs_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/statuses/{sha}","languages_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/languages","stargazers_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/stargazers","contributors_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/contributors","subscribers_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/subscribers","subscription_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/subscription","commits_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/contents/{+path}","compare_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/merges","archive_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/downloads","issues_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues{/number}","pulls_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls{/number}","milestones_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/milestones{/number}","notifications_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/labels{/name}","releases_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/releases{/id}","deployments_url":"https://api.github.com/repos/zednis/meeting-scheduler-api/deployments","created_at":"2018-02-24T17:36:57Z","updated_at":"2018-04-17T03:29:27Z","pushed_at":"2018-04-17T15:44:04Z","git_url":"git://github.com/zednis/meeting-scheduler-api.git","ssh_url":"git@github.com:zednis/meeting-scheduler-api.git","clone_url":"https://github.com/zednis/meeting-scheduler-api.git","svn_url":"https://github.com/zednis/meeting-scheduler-api","homepage":null,"size":652,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13"},"html":{"href":"https://github.com/zednis/meeting-scheduler-api/pull/13"},"issue":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/13"},"comments":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/zednis/meeting-scheduler-api/statuses/f0cc494a047400f3de943c40aac972dd24ba4f1f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"mwang25277"}}