{"action":"created","comment":{"url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/comments/56605863","id":56605863,"diff_hunk":"@@ -15,6 +16,52 @@ const UserFriend = db.define('friends', {});\n // will add methods to User (ex. User.getFriends())\n User.belongsToMany(User, { as: 'Friends', through: UserFriend });\n \n+User.getUserInfo = fbId => {\n+  User.findOne({ where: { fbId } })\n+    .then(user => {\n+      const token = jwt.encode(user, 'secret');\n+      const response = {\n+        user,\n+        token,\n+      };\n+      return response;\n+    })\n+    .catch(err => err);\n+};\n+\n+User.getUserFriends = user => getFriends().catch(err => err);\n+\n+User.findOrCreate = profile => {\n+  const name = profile.displayName;\n+  const picture = profile.photos[0].value;\n+  const fbId = {\n+    fbId: profile.id,\n+  };\n+  User.findOne(fbId)\n+    .then(match => {\n+      // create user if there's no match\n+      if (!match) {\n+        const newUser = {\n+          name,\n+          fbId,\n+          picture,\n+        };\n+        return User.create(newUser);\n+      }\n+      // if user already exists, update user entry in the database\n+      const updatedInfo = {\n+        name,\n+        picture,\n+      };\n+      return match.update(updatedInfo)\n+      .then(data => data)","path":"server/users/users.js","position":48,"original_position":48,"commit_id":"153c1740ebeb6aed111eb5d80a952197ce6d5cbb","original_commit_id":"153c1740ebeb6aed111eb5d80a952197ce6d5cbb","user":{"login":"abuddiga","id":4003102,"avatar_url":"https://avatars.githubusercontent.com/u/4003102?v=3","gravatar_id":"","url":"https://api.github.com/users/abuddiga","html_url":"https://github.com/abuddiga","followers_url":"https://api.github.com/users/abuddiga/followers","following_url":"https://api.github.com/users/abuddiga/following{/other_user}","gists_url":"https://api.github.com/users/abuddiga/gists{/gist_id}","starred_url":"https://api.github.com/users/abuddiga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abuddiga/subscriptions","organizations_url":"https://api.github.com/users/abuddiga/orgs","repos_url":"https://api.github.com/users/abuddiga/repos","events_url":"https://api.github.com/users/abuddiga/events{/privacy}","received_events_url":"https://api.github.com/users/abuddiga/received_events","type":"User","site_admin":false},"body":"Don't need these then and catches--it'll return the result of the update automatically and line 60 will catch","created_at":"2016-03-18T02:16:37Z","updated_at":"2016-03-18T02:16:37Z","html_url":"https://github.com/vivacioustoaster/vivacioustoaster/pull/77#discussion_r56605863","pull_request_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77","_links":{"self":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/comments/56605863"},"html":{"href":"https://github.com/vivacioustoaster/vivacioustoaster/pull/77#discussion_r56605863"},"pull_request":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77"}}},"pull_request":{"url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77","id":63311480,"html_url":"https://github.com/vivacioustoaster/vivacioustoaster/pull/77","diff_url":"https://github.com/vivacioustoaster/vivacioustoaster/pull/77.diff","patch_url":"https://github.com/vivacioustoaster/vivacioustoaster/pull/77.patch","issue_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues/77","number":77,"state":"open","locked":false,"title":"Back end user","user":{"login":"boyajay","id":13592079,"avatar_url":"https://avatars.githubusercontent.com/u/13592079?v=3","gravatar_id":"","url":"https://api.github.com/users/boyajay","html_url":"https://github.com/boyajay","followers_url":"https://api.github.com/users/boyajay/followers","following_url":"https://api.github.com/users/boyajay/following{/other_user}","gists_url":"https://api.github.com/users/boyajay/gists{/gist_id}","starred_url":"https://api.github.com/users/boyajay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boyajay/subscriptions","organizations_url":"https://api.github.com/users/boyajay/orgs","repos_url":"https://api.github.com/users/boyajay/repos","events_url":"https://api.github.com/users/boyajay/events{/privacy}","received_events_url":"https://api.github.com/users/boyajay/received_events","type":"User","site_admin":false},"body":"#### What's this PR do?\r\n1) Add functions to controller: getUser and getFriends\r\n2) Modulated out functions with DB interactions to the model file.\r\n#### Any background context you want to provide?\r\nfactored out DB interactions from server interactions for ease of testing\r\n#### What are the relevant tickets/issues?\r\nnone\r\n#### Where should the reviewer start?\r\nusers.js, usersController.js\r\n#### Are there tests written yet? How should this be manually tested?\r\nReady for tests to be written\r\n#### Screenshots (if appropriate)\r\n#### Questions:\r\n- Does this add new dependencies?\r\nno\r\n- Does our documentation need to be updated?\r\nno","created_at":"2016-03-18T00:07:31Z","updated_at":"2016-03-18T02:16:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0dfd3bf7d60d5fa0ddca3f37fe88390fc66468cf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77/commits","review_comments_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77/comments","review_comment_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues/77/comments","statuses_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/statuses/153c1740ebeb6aed111eb5d80a952197ce6d5cbb","head":{"label":"boyajay:backEnd-user","ref":"backEnd-user","sha":"153c1740ebeb6aed111eb5d80a952197ce6d5cbb","user":{"login":"boyajay","id":13592079,"avatar_url":"https://avatars.githubusercontent.com/u/13592079?v=3","gravatar_id":"","url":"https://api.github.com/users/boyajay","html_url":"https://github.com/boyajay","followers_url":"https://api.github.com/users/boyajay/followers","following_url":"https://api.github.com/users/boyajay/following{/other_user}","gists_url":"https://api.github.com/users/boyajay/gists{/gist_id}","starred_url":"https://api.github.com/users/boyajay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boyajay/subscriptions","organizations_url":"https://api.github.com/users/boyajay/orgs","repos_url":"https://api.github.com/users/boyajay/repos","events_url":"https://api.github.com/users/boyajay/events{/privacy}","received_events_url":"https://api.github.com/users/boyajay/received_events","type":"User","site_admin":false},"repo":{"id":53694479,"name":"vivacioustoaster","full_name":"boyajay/vivacioustoaster","owner":{"login":"boyajay","id":13592079,"avatar_url":"https://avatars.githubusercontent.com/u/13592079?v=3","gravatar_id":"","url":"https://api.github.com/users/boyajay","html_url":"https://github.com/boyajay","followers_url":"https://api.github.com/users/boyajay/followers","following_url":"https://api.github.com/users/boyajay/following{/other_user}","gists_url":"https://api.github.com/users/boyajay/gists{/gist_id}","starred_url":"https://api.github.com/users/boyajay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boyajay/subscriptions","organizations_url":"https://api.github.com/users/boyajay/orgs","repos_url":"https://api.github.com/users/boyajay/repos","events_url":"https://api.github.com/users/boyajay/events{/privacy}","received_events_url":"https://api.github.com/users/boyajay/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/boyajay/vivacioustoaster","description":"","fork":true,"url":"https://api.github.com/repos/boyajay/vivacioustoaster","forks_url":"https://api.github.com/repos/boyajay/vivacioustoaster/forks","keys_url":"https://api.github.com/repos/boyajay/vivacioustoaster/keys{/key_id}","collaborators_url":"https://api.github.com/repos/boyajay/vivacioustoaster/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/boyajay/vivacioustoaster/teams","hooks_url":"https://api.github.com/repos/boyajay/vivacioustoaster/hooks","issue_events_url":"https://api.github.com/repos/boyajay/vivacioustoaster/issues/events{/number}","events_url":"https://api.github.com/repos/boyajay/vivacioustoaster/events","assignees_url":"https://api.github.com/repos/boyajay/vivacioustoaster/assignees{/user}","branches_url":"https://api.github.com/repos/boyajay/vivacioustoaster/branches{/branch}","tags_url":"https://api.github.com/repos/boyajay/vivacioustoaster/tags","blobs_url":"https://api.github.com/repos/boyajay/vivacioustoaster/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/boyajay/vivacioustoaster/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/boyajay/vivacioustoaster/git/refs{/sha}","trees_url":"https://api.github.com/repos/boyajay/vivacioustoaster/git/trees{/sha}","statuses_url":"https://api.github.com/repos/boyajay/vivacioustoaster/statuses/{sha}","languages_url":"https://api.github.com/repos/boyajay/vivacioustoaster/languages","stargazers_url":"https://api.github.com/repos/boyajay/vivacioustoaster/stargazers","contributors_url":"https://api.github.com/repos/boyajay/vivacioustoaster/contributors","subscribers_url":"https://api.github.com/repos/boyajay/vivacioustoaster/subscribers","subscription_url":"https://api.github.com/repos/boyajay/vivacioustoaster/subscription","commits_url":"https://api.github.com/repos/boyajay/vivacioustoaster/commits{/sha}","git_commits_url":"https://api.github.com/repos/boyajay/vivacioustoaster/git/commits{/sha}","comments_url":"https://api.github.com/repos/boyajay/vivacioustoaster/comments{/number}","issue_comment_url":"https://api.github.com/repos/boyajay/vivacioustoaster/issues/comments{/number}","contents_url":"https://api.github.com/repos/boyajay/vivacioustoaster/contents/{+path}","compare_url":"https://api.github.com/repos/boyajay/vivacioustoaster/compare/{base}...{head}","merges_url":"https://api.github.com/repos/boyajay/vivacioustoaster/merges","archive_url":"https://api.github.com/repos/boyajay/vivacioustoaster/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/boyajay/vivacioustoaster/downloads","issues_url":"https://api.github.com/repos/boyajay/vivacioustoaster/issues{/number}","pulls_url":"https://api.github.com/repos/boyajay/vivacioustoaster/pulls{/number}","milestones_url":"https://api.github.com/repos/boyajay/vivacioustoaster/milestones{/number}","notifications_url":"https://api.github.com/repos/boyajay/vivacioustoaster/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/boyajay/vivacioustoaster/labels{/name}","releases_url":"https://api.github.com/repos/boyajay/vivacioustoaster/releases{/id}","deployments_url":"https://api.github.com/repos/boyajay/vivacioustoaster/deployments","created_at":"2016-03-11T20:21:26Z","updated_at":"2016-03-10T23:16:59Z","pushed_at":"2016-03-18T02:12:12Z","git_url":"git://github.com/boyajay/vivacioustoaster.git","ssh_url":"git@github.com:boyajay/vivacioustoaster.git","clone_url":"https://github.com/boyajay/vivacioustoaster.git","svn_url":"https://github.com/boyajay/vivacioustoaster","homepage":null,"size":2928,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"vivacioustoaster:master","ref":"master","sha":"17b90fa58bb8ad5bacaef7115be3c2f0d46af94c","user":{"login":"vivacioustoaster","id":17732369,"avatar_url":"https://avatars.githubusercontent.com/u/17732369?v=3","gravatar_id":"","url":"https://api.github.com/users/vivacioustoaster","html_url":"https://github.com/vivacioustoaster","followers_url":"https://api.github.com/users/vivacioustoaster/followers","following_url":"https://api.github.com/users/vivacioustoaster/following{/other_user}","gists_url":"https://api.github.com/users/vivacioustoaster/gists{/gist_id}","starred_url":"https://api.github.com/users/vivacioustoaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivacioustoaster/subscriptions","organizations_url":"https://api.github.com/users/vivacioustoaster/orgs","repos_url":"https://api.github.com/users/vivacioustoaster/repos","events_url":"https://api.github.com/users/vivacioustoaster/events{/privacy}","received_events_url":"https://api.github.com/users/vivacioustoaster/received_events","type":"Organization","site_admin":false},"repo":{"id":53624236,"name":"vivacioustoaster","full_name":"vivacioustoaster/vivacioustoaster","owner":{"login":"vivacioustoaster","id":17732369,"avatar_url":"https://avatars.githubusercontent.com/u/17732369?v=3","gravatar_id":"","url":"https://api.github.com/users/vivacioustoaster","html_url":"https://github.com/vivacioustoaster","followers_url":"https://api.github.com/users/vivacioustoaster/followers","following_url":"https://api.github.com/users/vivacioustoaster/following{/other_user}","gists_url":"https://api.github.com/users/vivacioustoaster/gists{/gist_id}","starred_url":"https://api.github.com/users/vivacioustoaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vivacioustoaster/subscriptions","organizations_url":"https://api.github.com/users/vivacioustoaster/orgs","repos_url":"https://api.github.com/users/vivacioustoaster/repos","events_url":"https://api.github.com/users/vivacioustoaster/events{/privacy}","received_events_url":"https://api.github.com/users/vivacioustoaster/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vivacioustoaster/vivacioustoaster","description":"","fork":false,"url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster","forks_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/forks","keys_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/teams","hooks_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/hooks","issue_events_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues/events{/number}","events_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/events","assignees_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/assignees{/user}","branches_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/branches{/branch}","tags_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/tags","blobs_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/git/refs{/sha}","trees_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/statuses/{sha}","languages_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/languages","stargazers_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/stargazers","contributors_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/contributors","subscribers_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/subscribers","subscription_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/subscription","commits_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/commits{/sha}","git_commits_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/git/commits{/sha}","comments_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/comments{/number}","issue_comment_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues/comments{/number}","contents_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/contents/{+path}","compare_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/merges","archive_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/downloads","issues_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues{/number}","pulls_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls{/number}","milestones_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/milestones{/number}","notifications_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/labels{/name}","releases_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/releases{/id}","deployments_url":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/deployments","created_at":"2016-03-10T23:16:59Z","updated_at":"2016-03-15T18:03:47Z","pushed_at":"2016-03-18T02:13:00Z","git_url":"git://github.com/vivacioustoaster/vivacioustoaster.git","ssh_url":"git@github.com:vivacioustoaster/vivacioustoaster.git","clone_url":"https://github.com/vivacioustoaster/vivacioustoaster.git","svn_url":"https://github.com/vivacioustoaster/vivacioustoaster","homepage":null,"size":97,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":46,"forks":4,"open_issues":46,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77"},"html":{"href":"https://github.com/vivacioustoaster/vivacioustoaster/pull/77"},"issue":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues/77"},"comments":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/issues/77/comments"},"review_comments":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77/comments"},"review_comment":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/pulls/77/commits"},"statuses":{"href":"https://api.github.com/repos/vivacioustoaster/vivacioustoaster/statuses/153c1740ebeb6aed111eb5d80a952197ce6d5cbb"}}}}