{"action":"created","comment":{"url":"https://api.github.com/repos/rogerxaic/andromeda/pulls/comments/235263524","pull_request_review_id":177088622,"id":235263524,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNTI2MzUyNA==","diff_hunk":"@@ -220,18 +221,29 @@ router.post('/:id/invitations',\n   (req, res) => {\n     if (!req.body.project) return res.status(400).json(errorToJson(new Error('You need to specify the project you want to invite this user to')));\n \n-    // TODO ensure that project and invited user exist\n-    let joinRequest = new JoinRequests({\n-      owner: req.user,\n-      invited: req.params.id,\n-      project: req.body.project\n-    });\n-    if (req.body.message) joinRequest.message = req.body.message;\n-\n-    joinRequest.save((err) => {\n-      if (err) return res.status(500).json(errorToJson(err));\n-      res.json(joinRequest);\n-    });\n+    Promise.all([\n+      Projects.findById(req.body.project).exec(),\n+      Users.findById(req.params.id).exec()\n+    ])\n+      .then(data => {\n+        if (!data[0] || !data[1]) throw new Error('Your request was not ok. Either the project or the user don\\'t exist.');\n+\n+        let joinRequest = new JoinRequests({\n+          owner: req.user,\n+          project: data[0],\n+          invited: data[1]\n+        });\n+        if (req.body.message) joinRequest.message = req.body.message;\n+\n+        return Promise.all([\n+          joinRequest.save(),\n+          Notifications.create({message: `You have been invited to project ${data[0].name}`, owner: req.params.id})","path":"server/routes/api/v1/users.js","position":44,"original_position":44,"commit_id":"d09035d36a67103631c14a0be555f1c21694e493","original_commit_id":"d09035d36a67103631c14a0be555f1c21694e493","user":{"login":"MateyByrd","id":7622933,"node_id":"MDQ6VXNlcjc2MjI5MzM=","avatar_url":"https://avatars1.githubusercontent.com/u/7622933?v=4","gravatar_id":"","url":"https://api.github.com/users/MateyByrd","html_url":"https://github.com/MateyByrd","followers_url":"https://api.github.com/users/MateyByrd/followers","following_url":"https://api.github.com/users/MateyByrd/following{/other_user}","gists_url":"https://api.github.com/users/MateyByrd/gists{/gist_id}","starred_url":"https://api.github.com/users/MateyByrd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MateyByrd/subscriptions","organizations_url":"https://api.github.com/users/MateyByrd/orgs","repos_url":"https://api.github.com/users/MateyByrd/repos","events_url":"https://api.github.com/users/MateyByrd/events{/privacy}","received_events_url":"https://api.github.com/users/MateyByrd/received_events","type":"User","site_admin":false},"body":"For easy navigation we can add this `a` tag to link to the project\r\n```suggestion\r\n          Notifications.create({message: `You have been invited to project <a href=\"/project/${data[0]._id}\">${data[0].name}</a>`, owner: req.params.id})\r\n```","created_at":"2018-11-21T06:12:20Z","updated_at":"2018-11-21T06:14:42Z","html_url":"https://github.com/rogerxaic/andromeda/pull/55#discussion_r235263524","pull_request_url":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/rogerxaic/andromeda/pulls/comments/235263524"},"html":{"href":"https://github.com/rogerxaic/andromeda/pull/55#discussion_r235263524"},"pull_request":{"href":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55"}}},"pull_request":{"url":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55","id":232478823,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMyNDc4ODIz","html_url":"https://github.com/rogerxaic/andromeda/pull/55","diff_url":"https://github.com/rogerxaic/andromeda/pull/55.diff","patch_url":"https://github.com/rogerxaic/andromeda/pull/55.patch","issue_url":"https://api.github.com/repos/rogerxaic/andromeda/issues/55","number":55,"state":"open","locked":false,"title":"add notifications when applying / inviting someone to a project.","user":{"login":"rogerxaic","id":10233725,"node_id":"MDQ6VXNlcjEwMjMzNzI1","avatar_url":"https://avatars1.githubusercontent.com/u/10233725?v=4","gravatar_id":"","url":"https://api.github.com/users/rogerxaic","html_url":"https://github.com/rogerxaic","followers_url":"https://api.github.com/users/rogerxaic/followers","following_url":"https://api.github.com/users/rogerxaic/following{/other_user}","gists_url":"https://api.github.com/users/rogerxaic/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerxaic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerxaic/subscriptions","organizations_url":"https://api.github.com/users/rogerxaic/orgs","repos_url":"https://api.github.com/users/rogerxaic/repos","events_url":"https://api.github.com/users/rogerxaic/events{/privacy}","received_events_url":"https://api.github.com/users/rogerxaic/received_events","type":"User","site_admin":false},"body":"also cleaned the code for users.js and added some tests (resolve a TODO).\r\nthis resolves #49 ","created_at":"2018-11-20T22:25:00Z","updated_at":"2018-11-21T06:14:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8de78019b006b3d7763a6c4c0b7ac1d5b557334e","assignee":null,"assignees":[],"requested_reviewers":[{"login":"robsel118","id":26892877,"node_id":"MDQ6VXNlcjI2ODkyODc3","avatar_url":"https://avatars1.githubusercontent.com/u/26892877?v=4","gravatar_id":"","url":"https://api.github.com/users/robsel118","html_url":"https://github.com/robsel118","followers_url":"https://api.github.com/users/robsel118/followers","following_url":"https://api.github.com/users/robsel118/following{/other_user}","gists_url":"https://api.github.com/users/robsel118/gists{/gist_id}","starred_url":"https://api.github.com/users/robsel118/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robsel118/subscriptions","organizations_url":"https://api.github.com/users/robsel118/orgs","repos_url":"https://api.github.com/users/robsel118/repos","events_url":"https://api.github.com/users/robsel118/events{/privacy}","received_events_url":"https://api.github.com/users/robsel118/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55/commits","review_comments_url":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55/comments","review_comment_url":"https://api.github.com/repos/rogerxaic/andromeda/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rogerxaic/andromeda/issues/55/comments","statuses_url":"https://api.github.com/repos/rogerxaic/andromeda/statuses/d09035d36a67103631c14a0be555f1c21694e493","head":{"label":"rogerxaic:join-project#31","ref":"join-project#31","sha":"d09035d36a67103631c14a0be555f1c21694e493","user":{"login":"rogerxaic","id":10233725,"node_id":"MDQ6VXNlcjEwMjMzNzI1","avatar_url":"https://avatars1.githubusercontent.com/u/10233725?v=4","gravatar_id":"","url":"https://api.github.com/users/rogerxaic","html_url":"https://github.com/rogerxaic","followers_url":"https://api.github.com/users/rogerxaic/followers","following_url":"https://api.github.com/users/rogerxaic/following{/other_user}","gists_url":"https://api.github.com/users/rogerxaic/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerxaic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerxaic/subscriptions","organizations_url":"https://api.github.com/users/rogerxaic/orgs","repos_url":"https://api.github.com/users/rogerxaic/repos","events_url":"https://api.github.com/users/rogerxaic/events{/privacy}","received_events_url":"https://api.github.com/users/rogerxaic/received_events","type":"User","site_admin":false},"repo":{"id":153627223,"node_id":"MDEwOlJlcG9zaXRvcnkxNTM2MjcyMjM=","name":"andromeda","full_name":"rogerxaic/andromeda","private":false,"owner":{"login":"rogerxaic","id":10233725,"node_id":"MDQ6VXNlcjEwMjMzNzI1","avatar_url":"https://avatars1.githubusercontent.com/u/10233725?v=4","gravatar_id":"","url":"https://api.github.com/users/rogerxaic","html_url":"https://github.com/rogerxaic","followers_url":"https://api.github.com/users/rogerxaic/followers","following_url":"https://api.github.com/users/rogerxaic/following{/other_user}","gists_url":"https://api.github.com/users/rogerxaic/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerxaic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerxaic/subscriptions","organizations_url":"https://api.github.com/users/rogerxaic/orgs","repos_url":"https://api.github.com/users/rogerxaic/repos","events_url":"https://api.github.com/users/rogerxaic/events{/privacy}","received_events_url":"https://api.github.com/users/rogerxaic/received_events","type":"User","site_admin":false},"html_url":"https://github.com/rogerxaic/andromeda","description":"Aalto project matchmaking tool for \"Design of WWW services\" course","fork":false,"url":"https://api.github.com/repos/rogerxaic/andromeda","forks_url":"https://api.github.com/repos/rogerxaic/andromeda/forks","keys_url":"https://api.github.com/repos/rogerxaic/andromeda/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rogerxaic/andromeda/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rogerxaic/andromeda/teams","hooks_url":"https://api.github.com/repos/rogerxaic/andromeda/hooks","issue_events_url":"https://api.github.com/repos/rogerxaic/andromeda/issues/events{/number}","events_url":"https://api.github.com/repos/rogerxaic/andromeda/events","assignees_url":"https://api.github.com/repos/rogerxaic/andromeda/assignees{/user}","branches_url":"https://api.github.com/repos/rogerxaic/andromeda/branches{/branch}","tags_url":"https://api.github.com/repos/rogerxaic/andromeda/tags","blobs_url":"https://api.github.com/repos/rogerxaic/andromeda/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rogerxaic/andromeda/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rogerxaic/andromeda/git/refs{/sha}","trees_url":"https://api.github.com/repos/rogerxaic/andromeda/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rogerxaic/andromeda/statuses/{sha}","languages_url":"https://api.github.com/repos/rogerxaic/andromeda/languages","stargazers_url":"https://api.github.com/repos/rogerxaic/andromeda/stargazers","contributors_url":"https://api.github.com/repos/rogerxaic/andromeda/contributors","subscribers_url":"https://api.github.com/repos/rogerxaic/andromeda/subscribers","subscription_url":"https://api.github.com/repos/rogerxaic/andromeda/subscription","commits_url":"https://api.github.com/repos/rogerxaic/andromeda/commits{/sha}","git_commits_url":"https://api.github.com/repos/rogerxaic/andromeda/git/commits{/sha}","comments_url":"https://api.github.com/repos/rogerxaic/andromeda/comments{/number}","issue_comment_url":"https://api.github.com/repos/rogerxaic/andromeda/issues/comments{/number}","contents_url":"https://api.github.com/repos/rogerxaic/andromeda/contents/{+path}","compare_url":"https://api.github.com/repos/rogerxaic/andromeda/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rogerxaic/andromeda/merges","archive_url":"https://api.github.com/repos/rogerxaic/andromeda/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rogerxaic/andromeda/downloads","issues_url":"https://api.github.com/repos/rogerxaic/andromeda/issues{/number}","pulls_url":"https://api.github.com/repos/rogerxaic/andromeda/pulls{/number}","milestones_url":"https://api.github.com/repos/rogerxaic/andromeda/milestones{/number}","notifications_url":"https://api.github.com/repos/rogerxaic/andromeda/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rogerxaic/andromeda/labels{/name}","releases_url":"https://api.github.com/repos/rogerxaic/andromeda/releases{/id}","deployments_url":"https://api.github.com/repos/rogerxaic/andromeda/deployments","created_at":"2018-10-18T13:20:58Z","updated_at":"2018-11-20T19:48:56Z","pushed_at":"2018-11-20T22:25:01Z","git_url":"git://github.com/rogerxaic/andromeda.git","ssh_url":"git@github.com:rogerxaic/andromeda.git","clone_url":"https://github.com/rogerxaic/andromeda.git","svn_url":"https://github.com/rogerxaic/andromeda","homepage":null,"size":559,"stargazers_count":0,"watchers_count":0,"language":"Vue","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":6,"license":null,"forks":0,"open_issues":6,"watchers":0,"default_branch":"master"}},"base":{"label":"rogerxaic:master","ref":"master","sha":"194dfc51e71837b28699ce01441ee4749f23c709","user":{"login":"rogerxaic","id":10233725,"node_id":"MDQ6VXNlcjEwMjMzNzI1","avatar_url":"https://avatars1.githubusercontent.com/u/10233725?v=4","gravatar_id":"","url":"https://api.github.com/users/rogerxaic","html_url":"https://github.com/rogerxaic","followers_url":"https://api.github.com/users/rogerxaic/followers","following_url":"https://api.github.com/users/rogerxaic/following{/other_user}","gists_url":"https://api.github.com/users/rogerxaic/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerxaic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerxaic/subscriptions","organizations_url":"https://api.github.com/users/rogerxaic/orgs","repos_url":"https://api.github.com/users/rogerxaic/repos","events_url":"https://api.github.com/users/rogerxaic/events{/privacy}","received_events_url":"https://api.github.com/users/rogerxaic/received_events","type":"User","site_admin":false},"repo":{"id":153627223,"node_id":"MDEwOlJlcG9zaXRvcnkxNTM2MjcyMjM=","name":"andromeda","full_name":"rogerxaic/andromeda","private":false,"owner":{"login":"rogerxaic","id":10233725,"node_id":"MDQ6VXNlcjEwMjMzNzI1","avatar_url":"https://avatars1.githubusercontent.com/u/10233725?v=4","gravatar_id":"","url":"https://api.github.com/users/rogerxaic","html_url":"https://github.com/rogerxaic","followers_url":"https://api.github.com/users/rogerxaic/followers","following_url":"https://api.github.com/users/rogerxaic/following{/other_user}","gists_url":"https://api.github.com/users/rogerxaic/gists{/gist_id}","starred_url":"https://api.github.com/users/rogerxaic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rogerxaic/subscriptions","organizations_url":"https://api.github.com/users/rogerxaic/orgs","repos_url":"https://api.github.com/users/rogerxaic/repos","events_url":"https://api.github.com/users/rogerxaic/events{/privacy}","received_events_url":"https://api.github.com/users/rogerxaic/received_events","type":"User","site_admin":false},"html_url":"https://github.com/rogerxaic/andromeda","description":"Aalto project matchmaking tool for \"Design of WWW services\" course","fork":false,"url":"https://api.github.com/repos/rogerxaic/andromeda","forks_url":"https://api.github.com/repos/rogerxaic/andromeda/forks","keys_url":"https://api.github.com/repos/rogerxaic/andromeda/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rogerxaic/andromeda/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rogerxaic/andromeda/teams","hooks_url":"https://api.github.com/repos/rogerxaic/andromeda/hooks","issue_events_url":"https://api.github.com/repos/rogerxaic/andromeda/issues/events{/number}","events_url":"https://api.github.com/repos/rogerxaic/andromeda/events","assignees_url":"https://api.github.com/repos/rogerxaic/andromeda/assignees{/user}","branches_url":"https://api.github.com/repos/rogerxaic/andromeda/branches{/branch}","tags_url":"https://api.github.com/repos/rogerxaic/andromeda/tags","blobs_url":"https://api.github.com/repos/rogerxaic/andromeda/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rogerxaic/andromeda/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rogerxaic/andromeda/git/refs{/sha}","trees_url":"https://api.github.com/repos/rogerxaic/andromeda/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rogerxaic/andromeda/statuses/{sha}","languages_url":"https://api.github.com/repos/rogerxaic/andromeda/languages","stargazers_url":"https://api.github.com/repos/rogerxaic/andromeda/stargazers","contributors_url":"https://api.github.com/repos/rogerxaic/andromeda/contributors","subscribers_url":"https://api.github.com/repos/rogerxaic/andromeda/subscribers","subscription_url":"https://api.github.com/repos/rogerxaic/andromeda/subscription","commits_url":"https://api.github.com/repos/rogerxaic/andromeda/commits{/sha}","git_commits_url":"https://api.github.com/repos/rogerxaic/andromeda/git/commits{/sha}","comments_url":"https://api.github.com/repos/rogerxaic/andromeda/comments{/number}","issue_comment_url":"https://api.github.com/repos/rogerxaic/andromeda/issues/comments{/number}","contents_url":"https://api.github.com/repos/rogerxaic/andromeda/contents/{+path}","compare_url":"https://api.github.com/repos/rogerxaic/andromeda/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rogerxaic/andromeda/merges","archive_url":"https://api.github.com/repos/rogerxaic/andromeda/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rogerxaic/andromeda/downloads","issues_url":"https://api.github.com/repos/rogerxaic/andromeda/issues{/number}","pulls_url":"https://api.github.com/repos/rogerxaic/andromeda/pulls{/number}","milestones_url":"https://api.github.com/repos/rogerxaic/andromeda/milestones{/number}","notifications_url":"https://api.github.com/repos/rogerxaic/andromeda/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rogerxaic/andromeda/labels{/name}","releases_url":"https://api.github.com/repos/rogerxaic/andromeda/releases{/id}","deployments_url":"https://api.github.com/repos/rogerxaic/andromeda/deployments","created_at":"2018-10-18T13:20:58Z","updated_at":"2018-11-20T19:48:56Z","pushed_at":"2018-11-20T22:25:01Z","git_url":"git://github.com/rogerxaic/andromeda.git","ssh_url":"git@github.com:rogerxaic/andromeda.git","clone_url":"https://github.com/rogerxaic/andromeda.git","svn_url":"https://github.com/rogerxaic/andromeda","homepage":null,"size":559,"stargazers_count":0,"watchers_count":0,"language":"Vue","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":6,"license":null,"forks":0,"open_issues":6,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55"},"html":{"href":"https://github.com/rogerxaic/andromeda/pull/55"},"issue":{"href":"https://api.github.com/repos/rogerxaic/andromeda/issues/55"},"comments":{"href":"https://api.github.com/repos/rogerxaic/andromeda/issues/55/comments"},"review_comments":{"href":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55/comments"},"review_comment":{"href":"https://api.github.com/repos/rogerxaic/andromeda/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rogerxaic/andromeda/pulls/55/commits"},"statuses":{"href":"https://api.github.com/repos/rogerxaic/andromeda/statuses/d09035d36a67103631c14a0be555f1c21694e493"}},"author_association":"OWNER"}}
{"actor":{"display_login":"MateyByrd"}}