{"action":"created","comment":{"url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/comments/277265256","pull_request_review_id":229018612,"id":277265256,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI3NzI2NTI1Ng==","diff_hunk":"@@ -0,0 +1,92 @@\n+require('dotenv').config();\n+\n+const config = require('./config');\n+\n+const { sumVotes } = require('./utils');\n+\n+const { db, writeTalk, addVote, auth } = require('./db');\n+\n+const express = require('express');\n+const bodyParser = require('body-parser')\n+const app = express();\n+\n+const authHeaderToUserId = async authHeader => {\n+  const m = authHeader && authHeader.match(/Bearer (.+)/);\n+\n+  if (!m) throw new Error('Request missing ID token');\n+\n+  const idToken = m[1];\n+  const decodedToken = await auth(idToken);\n+\n+  return decodedToken.user_id;\n+};\n+\n+app.use((req, res, next) => {\n+  res.header('Access-Control-Allow-Origin', '*');\n+  res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');\n+  next();\n+});\n+\n+app.use(bodyParser.json());\n+\n+app.get('/talks', async (req, res) => {\n+  const limit = +req.query.limit || config.DEFAULT_PAGE_LENGTH;\n+  const after = +req.query.after || 0;\n+\n+  const query = db.ref('talks');\n+\n+  const snapshot = await query.once('value');\n+\n+  const talks = snapshot.val();\n+\n+  Object.keys(talks).forEach(key => talks[key].votes = sumVotes(talks[key].votes));\n+\n+  res.json({\n+    talks\n+  });\n+});\n+\n+app.get('/talks/:id', async (req, res) => {\n+  const query = db.ref('talks/' + req.params.id);\n+\n+  const snapshot = await query.once('value');\n+\n+  const talk = snapshot.val();\n+  res.json(talk);\n+});\n+\n+app.post('/talks', async (req, res) => {\n+  const { title, abstract } = req.body;\n+\n+  if (title.length > 50 || abstract.length > 250) return;\n+\n+  const userId = await authHeaderToUserId(req.header('Authorization'));\n+\n+  const talk = { title, abstract, userId };\n+\n+  writeTalk(talk);\n+\n+  res.json(talk);\n+});\n+\n+app.post('/talks/:id/:vote', async (req, res) => {\n+  const vals = {\n+    upvote: +1,\n+    downvote: -1\n+  };","path":"api/index.js","position":76,"original_position":76,"commit_id":"3970135939144cd4d45febc2236a623e39d105de","original_commit_id":"3970135939144cd4d45febc2236a623e39d105de","user":{"login":"haishanh","id":1166872,"node_id":"MDQ6VXNlcjExNjY4NzI=","avatar_url":"https://avatars3.githubusercontent.com/u/1166872?v=4","gravatar_id":"","url":"https://api.github.com/users/haishanh","html_url":"https://github.com/haishanh","followers_url":"https://api.github.com/users/haishanh/followers","following_url":"https://api.github.com/users/haishanh/following{/other_user}","gists_url":"https://api.github.com/users/haishanh/gists{/gist_id}","starred_url":"https://api.github.com/users/haishanh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haishanh/subscriptions","organizations_url":"https://api.github.com/users/haishanh/orgs","repos_url":"https://api.github.com/users/haishanh/repos","events_url":"https://api.github.com/users/haishanh/events{/privacy}","received_events_url":"https://api.github.com/users/haishanh/received_events","type":"User","site_admin":false},"body":"Maybe `upvote` and `downvote` should be 2 separate fields? instead of `votes++` for an \"upvote\", `votes--` for an \"downvote\". Not a problem, I actually don't know how the real Hacker News models this.","created_at":"2019-04-22T11:06:33Z","updated_at":"2019-04-22T11:17:21Z","html_url":"https://github.com/Wiredcraft/test-fullstack/pull/30#discussion_r277265256","pull_request_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/comments/277265256"},"html":{"href":"https://github.com/Wiredcraft/test-fullstack/pull/30#discussion_r277265256"},"pull_request":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30","id":272233165,"node_id":"MDExOlB1bGxSZXF1ZXN0MjcyMjMzMTY1","html_url":"https://github.com/Wiredcraft/test-fullstack/pull/30","diff_url":"https://github.com/Wiredcraft/test-fullstack/pull/30.diff","patch_url":"https://github.com/Wiredcraft/test-fullstack/pull/30.patch","issue_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues/30","number":30,"state":"open","locked":false,"title":"Fullstack test","user":{"login":"lionel-rowe","id":26078826,"node_id":"MDQ6VXNlcjI2MDc4ODI2","avatar_url":"https://avatars0.githubusercontent.com/u/26078826?v=4","gravatar_id":"","url":"https://api.github.com/users/lionel-rowe","html_url":"https://github.com/lionel-rowe","followers_url":"https://api.github.com/users/lionel-rowe/followers","following_url":"https://api.github.com/users/lionel-rowe/following{/other_user}","gists_url":"https://api.github.com/users/lionel-rowe/gists{/gist_id}","starred_url":"https://api.github.com/users/lionel-rowe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionel-rowe/subscriptions","organizations_url":"https://api.github.com/users/lionel-rowe/orgs","repos_url":"https://api.github.com/users/lionel-rowe/repos","events_url":"https://api.github.com/users/lionel-rowe/events{/privacy}","received_events_url":"https://api.github.com/users/lionel-rowe/received_events","type":"User","site_admin":false},"body":"Front end:\r\n* React\r\n* Reach Router (better for a11y than React Router)\r\n* Sass\r\n* GitHub Pages\r\n\r\nBack end\r\n* Node\r\n* Express\r\n* Firebase\r\n* Heroku\r\n\r\nLive demo: https://lionel-rowe.github.io/test-fullstack/\r\n\r\nNote: login requires VPN (all other functionality should work without)","created_at":"2019-04-21T18:38:32Z","updated_at":"2019-04-22T11:17:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f79ab4b00996136ccaacf609df38ce7303f24334","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30/commits","review_comments_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30/comments","review_comment_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues/30/comments","statuses_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/statuses/3970135939144cd4d45febc2236a623e39d105de","head":{"label":"lionel-rowe:dev","ref":"dev","sha":"3970135939144cd4d45febc2236a623e39d105de","user":{"login":"lionel-rowe","id":26078826,"node_id":"MDQ6VXNlcjI2MDc4ODI2","avatar_url":"https://avatars0.githubusercontent.com/u/26078826?v=4","gravatar_id":"","url":"https://api.github.com/users/lionel-rowe","html_url":"https://github.com/lionel-rowe","followers_url":"https://api.github.com/users/lionel-rowe/followers","following_url":"https://api.github.com/users/lionel-rowe/following{/other_user}","gists_url":"https://api.github.com/users/lionel-rowe/gists{/gist_id}","starred_url":"https://api.github.com/users/lionel-rowe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionel-rowe/subscriptions","organizations_url":"https://api.github.com/users/lionel-rowe/orgs","repos_url":"https://api.github.com/users/lionel-rowe/repos","events_url":"https://api.github.com/users/lionel-rowe/events{/privacy}","received_events_url":"https://api.github.com/users/lionel-rowe/received_events","type":"User","site_admin":false},"repo":{"id":181478970,"node_id":"MDEwOlJlcG9zaXRvcnkxODE0Nzg5NzA=","name":"test-fullstack","full_name":"lionel-rowe/test-fullstack","private":false,"owner":{"login":"lionel-rowe","id":26078826,"node_id":"MDQ6VXNlcjI2MDc4ODI2","avatar_url":"https://avatars0.githubusercontent.com/u/26078826?v=4","gravatar_id":"","url":"https://api.github.com/users/lionel-rowe","html_url":"https://github.com/lionel-rowe","followers_url":"https://api.github.com/users/lionel-rowe/followers","following_url":"https://api.github.com/users/lionel-rowe/following{/other_user}","gists_url":"https://api.github.com/users/lionel-rowe/gists{/gist_id}","starred_url":"https://api.github.com/users/lionel-rowe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionel-rowe/subscriptions","organizations_url":"https://api.github.com/users/lionel-rowe/orgs","repos_url":"https://api.github.com/users/lionel-rowe/repos","events_url":"https://api.github.com/users/lionel-rowe/events{/privacy}","received_events_url":"https://api.github.com/users/lionel-rowe/received_events","type":"User","site_admin":false},"html_url":"https://github.com/lionel-rowe/test-fullstack","description":null,"fork":true,"url":"https://api.github.com/repos/lionel-rowe/test-fullstack","forks_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/forks","keys_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/teams","hooks_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/hooks","issue_events_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/issues/events{/number}","events_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/events","assignees_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/assignees{/user}","branches_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/branches{/branch}","tags_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/tags","blobs_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/git/refs{/sha}","trees_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/statuses/{sha}","languages_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/languages","stargazers_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/stargazers","contributors_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/contributors","subscribers_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/subscribers","subscription_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/subscription","commits_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/commits{/sha}","git_commits_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/git/commits{/sha}","comments_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/comments{/number}","issue_comment_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/issues/comments{/number}","contents_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/contents/{+path}","compare_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/merges","archive_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/downloads","issues_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/issues{/number}","pulls_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/pulls{/number}","milestones_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/milestones{/number}","notifications_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/labels{/name}","releases_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/releases{/id}","deployments_url":"https://api.github.com/repos/lionel-rowe/test-fullstack/deployments","created_at":"2019-04-15T12:09:47Z","updated_at":"2019-04-21T18:27:47Z","pushed_at":"2019-04-21T18:27:44Z","git_url":"git://github.com/lionel-rowe/test-fullstack.git","ssh_url":"git@github.com:lionel-rowe/test-fullstack.git","clone_url":"https://github.com/lionel-rowe/test-fullstack.git","svn_url":"https://github.com/lionel-rowe/test-fullstack","homepage":"https://lionel-rowe.github.io/test-fullstack/","size":6928,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Wiredcraft:master","ref":"master","sha":"bb479c596a6d5bd605e9b1f610982173ba09d52e","user":{"login":"Wiredcraft","id":496772,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ5Njc3Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/496772?v=4","gravatar_id":"","url":"https://api.github.com/users/Wiredcraft","html_url":"https://github.com/Wiredcraft","followers_url":"https://api.github.com/users/Wiredcraft/followers","following_url":"https://api.github.com/users/Wiredcraft/following{/other_user}","gists_url":"https://api.github.com/users/Wiredcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/Wiredcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wiredcraft/subscriptions","organizations_url":"https://api.github.com/users/Wiredcraft/orgs","repos_url":"https://api.github.com/users/Wiredcraft/repos","events_url":"https://api.github.com/users/Wiredcraft/events{/privacy}","received_events_url":"https://api.github.com/users/Wiredcraft/received_events","type":"Organization","site_admin":false},"repo":{"id":27256548,"node_id":"MDEwOlJlcG9zaXRvcnkyNzI1NjU0OA==","name":"test-fullstack","full_name":"Wiredcraft/test-fullstack","private":false,"owner":{"login":"Wiredcraft","id":496772,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ5Njc3Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/496772?v=4","gravatar_id":"","url":"https://api.github.com/users/Wiredcraft","html_url":"https://github.com/Wiredcraft","followers_url":"https://api.github.com/users/Wiredcraft/followers","following_url":"https://api.github.com/users/Wiredcraft/following{/other_user}","gists_url":"https://api.github.com/users/Wiredcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/Wiredcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Wiredcraft/subscriptions","organizations_url":"https://api.github.com/users/Wiredcraft/orgs","repos_url":"https://api.github.com/users/Wiredcraft/repos","events_url":"https://api.github.com/users/Wiredcraft/events{/privacy}","received_events_url":"https://api.github.com/users/Wiredcraft/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/Wiredcraft/test-fullstack","description":null,"fork":false,"url":"https://api.github.com/repos/Wiredcraft/test-fullstack","forks_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/forks","keys_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/teams","hooks_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/hooks","issue_events_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues/events{/number}","events_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/events","assignees_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/assignees{/user}","branches_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/branches{/branch}","tags_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/tags","blobs_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/git/refs{/sha}","trees_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/statuses/{sha}","languages_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/languages","stargazers_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/stargazers","contributors_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/contributors","subscribers_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/subscribers","subscription_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/subscription","commits_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/commits{/sha}","git_commits_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/git/commits{/sha}","comments_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/comments{/number}","issue_comment_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues/comments{/number}","contents_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/contents/{+path}","compare_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/merges","archive_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/downloads","issues_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues{/number}","pulls_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls{/number}","milestones_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/milestones{/number}","notifications_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/labels{/name}","releases_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/releases{/id}","deployments_url":"https://api.github.com/repos/Wiredcraft/test-fullstack/deployments","created_at":"2014-11-28T07:38:20Z","updated_at":"2019-04-01T05:59:11Z","pushed_at":"2019-04-21T18:38:33Z","git_url":"git://github.com/Wiredcraft/test-fullstack.git","ssh_url":"git@github.com:Wiredcraft/test-fullstack.git","clone_url":"https://github.com/Wiredcraft/test-fullstack.git","svn_url":"https://github.com/Wiredcraft/test-fullstack","homepage":null,"size":8,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":17,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"forks":17,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30"},"html":{"href":"https://github.com/Wiredcraft/test-fullstack/pull/30"},"issue":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues/30"},"comments":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/Wiredcraft/test-fullstack/statuses/3970135939144cd4d45febc2236a623e39d105de"}},"author_association":"NONE"}}
{"actor":{"display_login":"haishanh"}}