{"action":"created","comment":{"url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/comments/213607957","pull_request_review_id":150477424,"id":213607957,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMzYwNzk1Nw==","diff_hunk":"@@ -167,7 +167,79 @@ const answerQueries = {\n       values: [answerId, value],\n     };\n   },\n+\n };\n \n+const voteQueries = {\n+  /**\n+   * Vote answer query function\n+   * @param {Array} array Array consisting of the query parameters\n+   * @returns {object} Vote answer query object\n+   */\n+  voteAnswer(array) {\n+    return {\n+      text: `\n+      INSERT INTO votes\n+      (answerid, userid, votestatus)\n+      VALUES ($1, $2, $3)\n+      RETURNING votestatus,\n+      COALESCE((SELECT COUNT (v.id) FROM votes v \n+      WHERE v.answerid = $1 \n+      AND v.votestatus = 1 GROUP BY answerid),0) as upvotes,\n \n-export default { userQueries, questionQueries, answerQueries };\n+      COALESCE((SELECT COUNT (v.id) FROM votes v \n+      WHERE v.answerid = $1\n+      AND v.votestatus = 0 GROUP BY answerid),0) as downvotes\n+      `,\n+      values: array,\n+    };\n+  },\n+  /**\n+   * Get votes query function\n+   * @param {number} answerId Answer id\n+   * @param {number} userId User id\n+   * @returns {object} Get votes query object\n+   */\n+  getUserVote(answerId, userId) {\n+    return {\n+      text: `\n+      SELECT v.id,\n+      v.votestatus\n+      FROM votes v\n+      WHERE v.answerid = $1 AND v.userid = $2\n+      `,\n+      values: [answerId, userId],\n+    };\n+  },\n+  /**\n+   * Update vote query function\n+   * @param {number} voteId Vote id\n+   * @param {number} voteStatus Vote status\n+   * @returns {object} Update vote query object\n+   */\n+  updateVote(voteId, voteStatus) {\n+    return {\n+      text: `\n+      UPDATE votes\n+      SET votestatus = $2\n+      WHERE id = $1\n+      RETURNING votestatus,\n+      COALESCE((SELECT COUNT (v.id) FROM votes v \n+      WHERE v.answerid = $1 \n+      AND v.votestatus = 1 GROUP BY answerid),0) as upvotes,\n+\n+      COALESCE((SELECT COUNT (v.id) FROM votes v \n+      WHERE v.answerid = $1\n+      AND v.votestatus = 0 GROUP BY answerid),0) as downvotes\n+      `,\n+      values: [voteId, voteStatus],\n+    };\n+  },\n+};\n+\n+export default {\n+  userQueries,\n+  questionQueries,","path":"server/helpers/queries.js","position":86,"original_position":86,"commit_id":"5c92d78021415f24f33f31846e3480cd8efca793","original_commit_id":"5c92d78021415f24f33f31846e3480cd8efca793","user":{"login":"houndci-bot","id":6697940,"node_id":"MDQ6VXNlcjY2OTc5NDA=","avatar_url":"https://avatars0.githubusercontent.com/u/6697940?v=4","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"'object short notation' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).","created_at":"2018-08-29T09:32:01Z","updated_at":"2018-08-29T09:32:04Z","html_url":"https://github.com/PriscillaSam/Stackoverflow-Lite/pull/24#discussion_r213607957","pull_request_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/comments/213607957"},"html":{"href":"https://github.com/PriscillaSam/Stackoverflow-Lite/pull/24#discussion_r213607957"},"pull_request":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24"}}},"pull_request":{"url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24","id":211687439,"node_id":"MDExOlB1bGxSZXF1ZXN0MjExNjg3NDM5","html_url":"https://github.com/PriscillaSam/Stackoverflow-Lite/pull/24","diff_url":"https://github.com/PriscillaSam/Stackoverflow-Lite/pull/24.diff","patch_url":"https://github.com/PriscillaSam/Stackoverflow-Lite/pull/24.patch","issue_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/24","number":24,"state":"open","locked":false,"title":"#160022206 Modify api endpoint to vote an answer","user":{"login":"PriscillaSam","id":29674347,"node_id":"MDQ6VXNlcjI5Njc0MzQ3","avatar_url":"https://avatars1.githubusercontent.com/u/29674347?v=4","gravatar_id":"","url":"https://api.github.com/users/PriscillaSam","html_url":"https://github.com/PriscillaSam","followers_url":"https://api.github.com/users/PriscillaSam/followers","following_url":"https://api.github.com/users/PriscillaSam/following{/other_user}","gists_url":"https://api.github.com/users/PriscillaSam/gists{/gist_id}","starred_url":"https://api.github.com/users/PriscillaSam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PriscillaSam/subscriptions","organizations_url":"https://api.github.com/users/PriscillaSam/orgs","repos_url":"https://api.github.com/users/PriscillaSam/repos","events_url":"https://api.github.com/users/PriscillaSam/events{/privacy}","received_events_url":"https://api.github.com/users/PriscillaSam/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\nModify api endpoint **POST** `api/v1/answers/:id` to interact with a database.\r\n\r\n#### Description of Task to be completed?\r\n- Connect endpoint to database.\r\n- Write sql queries to add and update votes from database.\r\n- Refactor tests to use database.\r\n\r\n#### How should this be manually tested?\r\n* Clone the repo using `git clone https://github.com/PriscillaSam/Stackoverflow-Lite.git`.\r\n* run `git checkout ft-vote-answer-160022206 `.\r\n* run `npm install` and `npm run start:dev`.\r\n* Open up Postman and test **POST** `localhost:3000/api/v1/answers/:id`.\r\n*Note*: You need to be authenticated to perform this operation. So signup by providing your name, email, password and confirm password or login using this sample data:\r\n```gherkin\r\n{\r\n   email: \"garry.doe@gmail.com\",\r\n   password: \"password\"\r\n}\r\n```\r\n\r\n#### Any background context you want to provide?\r\nNone.\r\n\r\n#### What are the relevant pivotal tracker stories?\r\n#160022206","created_at":"2018-08-29T09:31:49Z","updated_at":"2018-08-29T09:32:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ea959347de38be19e920583fd4b60a43b2d49f55","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24/commits","review_comments_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24/comments","review_comment_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/24/comments","statuses_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/statuses/5c92d78021415f24f33f31846e3480cd8efca793","head":{"label":"PriscillaSam:ft-vote-answer-160022206","ref":"ft-vote-answer-160022206","sha":"5c92d78021415f24f33f31846e3480cd8efca793","user":{"login":"PriscillaSam","id":29674347,"node_id":"MDQ6VXNlcjI5Njc0MzQ3","avatar_url":"https://avatars1.githubusercontent.com/u/29674347?v=4","gravatar_id":"","url":"https://api.github.com/users/PriscillaSam","html_url":"https://github.com/PriscillaSam","followers_url":"https://api.github.com/users/PriscillaSam/followers","following_url":"https://api.github.com/users/PriscillaSam/following{/other_user}","gists_url":"https://api.github.com/users/PriscillaSam/gists{/gist_id}","starred_url":"https://api.github.com/users/PriscillaSam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PriscillaSam/subscriptions","organizations_url":"https://api.github.com/users/PriscillaSam/orgs","repos_url":"https://api.github.com/users/PriscillaSam/repos","events_url":"https://api.github.com/users/PriscillaSam/events{/privacy}","received_events_url":"https://api.github.com/users/PriscillaSam/received_events","type":"User","site_admin":false},"repo":{"id":143856339,"node_id":"MDEwOlJlcG9zaXRvcnkxNDM4NTYzMzk=","name":"Stackoverflow-Lite","full_name":"PriscillaSam/Stackoverflow-Lite","owner":{"login":"PriscillaSam","id":29674347,"node_id":"MDQ6VXNlcjI5Njc0MzQ3","avatar_url":"https://avatars1.githubusercontent.com/u/29674347?v=4","gravatar_id":"","url":"https://api.github.com/users/PriscillaSam","html_url":"https://github.com/PriscillaSam","followers_url":"https://api.github.com/users/PriscillaSam/followers","following_url":"https://api.github.com/users/PriscillaSam/following{/other_user}","gists_url":"https://api.github.com/users/PriscillaSam/gists{/gist_id}","starred_url":"https://api.github.com/users/PriscillaSam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PriscillaSam/subscriptions","organizations_url":"https://api.github.com/users/PriscillaSam/orgs","repos_url":"https://api.github.com/users/PriscillaSam/repos","events_url":"https://api.github.com/users/PriscillaSam/events{/privacy}","received_events_url":"https://api.github.com/users/PriscillaSam/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PriscillaSam/Stackoverflow-Lite","description":null,"fork":false,"url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite","forks_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/forks","keys_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/teams","hooks_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/hooks","issue_events_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/events{/number}","events_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/events","assignees_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/assignees{/user}","branches_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/branches{/branch}","tags_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/tags","blobs_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/refs{/sha}","trees_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/statuses/{sha}","languages_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/languages","stargazers_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/stargazers","contributors_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/contributors","subscribers_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/subscribers","subscription_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/subscription","commits_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/commits{/sha}","git_commits_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/commits{/sha}","comments_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/comments{/number}","issue_comment_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/comments{/number}","contents_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/contents/{+path}","compare_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/merges","archive_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/downloads","issues_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues{/number}","pulls_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls{/number}","milestones_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/milestones{/number}","notifications_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/labels{/name}","releases_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/releases{/id}","deployments_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/deployments","created_at":"2018-08-07T10:16:04Z","updated_at":"2018-08-27T03:01:49Z","pushed_at":"2018-08-29T09:31:50Z","git_url":"git://github.com/PriscillaSam/Stackoverflow-Lite.git","ssh_url":"git@github.com:PriscillaSam/Stackoverflow-Lite.git","clone_url":"https://github.com/PriscillaSam/Stackoverflow-Lite.git","svn_url":"https://github.com/PriscillaSam/Stackoverflow-Lite","homepage":null,"size":1611,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"PriscillaSam:challenge3","ref":"challenge3","sha":"8280d87af9b5021e5b30b22225fc1e7020363073","user":{"login":"PriscillaSam","id":29674347,"node_id":"MDQ6VXNlcjI5Njc0MzQ3","avatar_url":"https://avatars1.githubusercontent.com/u/29674347?v=4","gravatar_id":"","url":"https://api.github.com/users/PriscillaSam","html_url":"https://github.com/PriscillaSam","followers_url":"https://api.github.com/users/PriscillaSam/followers","following_url":"https://api.github.com/users/PriscillaSam/following{/other_user}","gists_url":"https://api.github.com/users/PriscillaSam/gists{/gist_id}","starred_url":"https://api.github.com/users/PriscillaSam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PriscillaSam/subscriptions","organizations_url":"https://api.github.com/users/PriscillaSam/orgs","repos_url":"https://api.github.com/users/PriscillaSam/repos","events_url":"https://api.github.com/users/PriscillaSam/events{/privacy}","received_events_url":"https://api.github.com/users/PriscillaSam/received_events","type":"User","site_admin":false},"repo":{"id":143856339,"node_id":"MDEwOlJlcG9zaXRvcnkxNDM4NTYzMzk=","name":"Stackoverflow-Lite","full_name":"PriscillaSam/Stackoverflow-Lite","owner":{"login":"PriscillaSam","id":29674347,"node_id":"MDQ6VXNlcjI5Njc0MzQ3","avatar_url":"https://avatars1.githubusercontent.com/u/29674347?v=4","gravatar_id":"","url":"https://api.github.com/users/PriscillaSam","html_url":"https://github.com/PriscillaSam","followers_url":"https://api.github.com/users/PriscillaSam/followers","following_url":"https://api.github.com/users/PriscillaSam/following{/other_user}","gists_url":"https://api.github.com/users/PriscillaSam/gists{/gist_id}","starred_url":"https://api.github.com/users/PriscillaSam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PriscillaSam/subscriptions","organizations_url":"https://api.github.com/users/PriscillaSam/orgs","repos_url":"https://api.github.com/users/PriscillaSam/repos","events_url":"https://api.github.com/users/PriscillaSam/events{/privacy}","received_events_url":"https://api.github.com/users/PriscillaSam/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/PriscillaSam/Stackoverflow-Lite","description":null,"fork":false,"url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite","forks_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/forks","keys_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/teams","hooks_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/hooks","issue_events_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/events{/number}","events_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/events","assignees_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/assignees{/user}","branches_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/branches{/branch}","tags_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/tags","blobs_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/refs{/sha}","trees_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/statuses/{sha}","languages_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/languages","stargazers_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/stargazers","contributors_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/contributors","subscribers_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/subscribers","subscription_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/subscription","commits_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/commits{/sha}","git_commits_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/git/commits{/sha}","comments_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/comments{/number}","issue_comment_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/comments{/number}","contents_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/contents/{+path}","compare_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/merges","archive_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/downloads","issues_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues{/number}","pulls_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls{/number}","milestones_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/milestones{/number}","notifications_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/labels{/name}","releases_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/releases{/id}","deployments_url":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/deployments","created_at":"2018-08-07T10:16:04Z","updated_at":"2018-08-27T03:01:49Z","pushed_at":"2018-08-29T09:31:50Z","git_url":"git://github.com/PriscillaSam/Stackoverflow-Lite.git","ssh_url":"git@github.com:PriscillaSam/Stackoverflow-Lite.git","clone_url":"https://github.com/PriscillaSam/Stackoverflow-Lite.git","svn_url":"https://github.com/PriscillaSam/Stackoverflow-Lite","homepage":null,"size":1611,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24"},"html":{"href":"https://github.com/PriscillaSam/Stackoverflow-Lite/pull/24"},"issue":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/24"},"comments":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/issues/24/comments"},"review_comments":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24/comments"},"review_comment":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/pulls/24/commits"},"statuses":{"href":"https://api.github.com/repos/PriscillaSam/Stackoverflow-Lite/statuses/5c92d78021415f24f33f31846e3480cd8efca793"}},"author_association":"OWNER"}}
{"actor":{"display_login":"houndci-bot"}}