{"action":"created","comment":{"url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/comments/191676207","pull_request_review_id":124290021,"id":191676207,"diff_hunk":"@@ -23,14 +23,49 @@ const requestCheck = (req, res, next) => {\n   client.connect();\n   client.query(queryString, (error, result) => {\n     client.end();\n-    if (result.rows[0]) {\n+    if (!result.rows[0]) { return res.status(404).json({ status: 'error', code: 404, message: 'Request does not exist' }); }\n+    const { status } = result.rows[0];\n+    if (status === 'pending') {\n+      return next();\n+    }\n+    return res.status(400)\n+      .json({\n+        status: 'error',\n+        code: 400,\n+        message: 'Request can no longer be approved or disapproved',\n+      });\n+  });\n+};\n+\n+/**\n+   * Checks if the request exists on the system and is approved\n+   *\n+   * @param {object} req - The request object received\n+   * @param {object} res - The response object sent\n+   * @param {object} next - The next middleware\n+   */\n+const requestCheckApprove = (req, res, next) => {\n+  const { requestId } = req.params;\n+  const queryString = {\n+    text: 'SELECT * FROM requests WHERE id = $1 LIMIT 1;',\n+    values: [requestId],\n+  };\n+  const client = new Client({\n+    connectionString,\n+  });\n+  client.connect();\n+  client.query(queryString, (error, result) => {\n+    client.end();\n+    if (!result.rows[0]) { return res.status(404).json({ status: 'error', code: 404, message: 'Request does not exist' }); }\n+    const { status } = result.rows[0];\n+    if (status === 'approved') {","path":"Server/middlewares/checkRequest.js","position":56,"original_position":56,"commit_id":"fc5f7d97eaf0ae3724850b0550e43387e883178c","original_commit_id":"fc5f7d97eaf0ae3724850b0550e43387e883178c","user":{"login":"benfluleck","id":26222856,"avatar_url":"https://avatars2.githubusercontent.com/u/26222856?v=4","gravatar_id":"","url":"https://api.github.com/users/benfluleck","html_url":"https://github.com/benfluleck","followers_url":"https://api.github.com/users/benfluleck/followers","following_url":"https://api.github.com/users/benfluleck/following{/other_user}","gists_url":"https://api.github.com/users/benfluleck/gists{/gist_id}","starred_url":"https://api.github.com/users/benfluleck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benfluleck/subscriptions","organizations_url":"https://api.github.com/users/benfluleck/orgs","repos_url":"https://api.github.com/users/benfluleck/repos","events_url":"https://api.github.com/users/benfluleck/events{/privacy}","received_events_url":"https://api.github.com/users/benfluleck/received_events","type":"User","site_admin":false},"body":"**Nitpick**\r\nIs there a benefit by setting the status to approved as opposed to using a number for the status codes e.g. 1 for approved, 2 for rejected. I feel using this way it's a quicker process and it is not as tightly coupled.","created_at":"2018-05-30T08:07:06Z","updated_at":"2018-05-30T08:13:02Z","html_url":"https://github.com/chukwuemekachm/Maintenance-Tracker/pull/52#discussion_r191676207","pull_request_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/comments/191676207"},"html":{"href":"https://github.com/chukwuemekachm/Maintenance-Tracker/pull/52#discussion_r191676207"},"pull_request":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52"}}},"pull_request":{"url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52","id":191332006,"html_url":"https://github.com/chukwuemekachm/Maintenance-Tracker/pull/52","diff_url":"https://github.com/chukwuemekachm/Maintenance-Tracker/pull/52.diff","patch_url":"https://github.com/chukwuemekachm/Maintenance-Tracker/pull/52.patch","issue_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/52","number":52,"state":"open","locked":false,"title":"#157891041 Resolves bugs in admin approve and resolve endpoints","user":{"login":"chukwuemekachm","id":33798252,"avatar_url":"https://avatars0.githubusercontent.com/u/33798252?v=4","gravatar_id":"","url":"https://api.github.com/users/chukwuemekachm","html_url":"https://github.com/chukwuemekachm","followers_url":"https://api.github.com/users/chukwuemekachm/followers","following_url":"https://api.github.com/users/chukwuemekachm/following{/other_user}","gists_url":"https://api.github.com/users/chukwuemekachm/gists{/gist_id}","starred_url":"https://api.github.com/users/chukwuemekachm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chukwuemekachm/subscriptions","organizations_url":"https://api.github.com/users/chukwuemekachm/orgs","repos_url":"https://api.github.com/users/chukwuemekachm/repos","events_url":"https://api.github.com/users/chukwuemekachm/events{/privacy}","received_events_url":"https://api.github.com/users/chukwuemekachm/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\n- Resolves bugs in admin approve, disapprove and resolve endpoints\r\n#### Description of Task to be completed?\r\n- Write tests for endpoints\r\n- Modidy api/v1/requests/:requestId/approve\r\n- Modidy api/v1/requests/:requestId/disapprove\r\n- Modidy api/v1/requests/:requestId/resolve\r\n- Test endpoint using Postman\r\n- Enable cors on server\r\n#### How should this be manually tested?\r\n- Clone the repo\r\n- Startup command line\r\n- cd to project root\r\n- run ``` npm install ```\r\n- run ``` npm run migrate ```\r\n- run ``` npm run start:dev ```\r\n- Test endpoint using Postman\r\n#### Any background context you want to provide?\r\n- Add a ``` .env ``` file to the project root\r\n- In the ``` .env ``` file set the DATABASE_URL to the `URL` your preferred database\r\n#### What are the relevant pivotal tracker stories?\r\n- #157891041\r\n#### Screenshots (if appropriate)\r\n\r\n![screenshot 192](https://user-images.githubusercontent.com/33798252/40699129-8d2f004e-63ca-11e8-83db-91ceef2f8ebf.png)\r\n\r\n![screenshot 193](https://user-images.githubusercontent.com/33798252/40699149-ab4d9932-63ca-11e8-92a3-35d485496b96.png)\r\n\r\n![screenshot 194](https://user-images.githubusercontent.com/33798252/40699200-f06affc8-63ca-11e8-898b-3d15ca9b3030.png)\r\n\r\n#### Questions:\r\n- None","created_at":"2018-05-30T04:34:01Z","updated_at":"2018-05-30T08:13:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"50caef76e8b1d79d224b01541a70323382b3f0e4","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52/commits","review_comments_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52/comments","review_comment_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/52/comments","statuses_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/statuses/fc5f7d97eaf0ae3724850b0550e43387e883178c","head":{"label":"chukwuemekachm:bg-fix-admin-endpoints-157891041","ref":"bg-fix-admin-endpoints-157891041","sha":"fc5f7d97eaf0ae3724850b0550e43387e883178c","user":{"login":"chukwuemekachm","id":33798252,"avatar_url":"https://avatars0.githubusercontent.com/u/33798252?v=4","gravatar_id":"","url":"https://api.github.com/users/chukwuemekachm","html_url":"https://github.com/chukwuemekachm","followers_url":"https://api.github.com/users/chukwuemekachm/followers","following_url":"https://api.github.com/users/chukwuemekachm/following{/other_user}","gists_url":"https://api.github.com/users/chukwuemekachm/gists{/gist_id}","starred_url":"https://api.github.com/users/chukwuemekachm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chukwuemekachm/subscriptions","organizations_url":"https://api.github.com/users/chukwuemekachm/orgs","repos_url":"https://api.github.com/users/chukwuemekachm/repos","events_url":"https://api.github.com/users/chukwuemekachm/events{/privacy}","received_events_url":"https://api.github.com/users/chukwuemekachm/received_events","type":"User","site_admin":false},"repo":{"id":133387421,"name":"Maintenance-Tracker","full_name":"chukwuemekachm/Maintenance-Tracker","owner":{"login":"chukwuemekachm","id":33798252,"avatar_url":"https://avatars0.githubusercontent.com/u/33798252?v=4","gravatar_id":"","url":"https://api.github.com/users/chukwuemekachm","html_url":"https://github.com/chukwuemekachm","followers_url":"https://api.github.com/users/chukwuemekachm/followers","following_url":"https://api.github.com/users/chukwuemekachm/following{/other_user}","gists_url":"https://api.github.com/users/chukwuemekachm/gists{/gist_id}","starred_url":"https://api.github.com/users/chukwuemekachm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chukwuemekachm/subscriptions","organizations_url":"https://api.github.com/users/chukwuemekachm/orgs","repos_url":"https://api.github.com/users/chukwuemekachm/repos","events_url":"https://api.github.com/users/chukwuemekachm/events{/privacy}","received_events_url":"https://api.github.com/users/chukwuemekachm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chukwuemekachm/Maintenance-Tracker","description":"Maintenance Tracker App is an application that provides users with the ability to reach out to operations or repairs department regarding repair or maintenance requests and monitor the status of their request.","fork":false,"url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker","forks_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/forks","keys_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/teams","hooks_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/hooks","issue_events_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/events{/number}","events_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/events","assignees_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/assignees{/user}","branches_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/branches{/branch}","tags_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/tags","blobs_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/refs{/sha}","trees_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/statuses/{sha}","languages_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/languages","stargazers_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/stargazers","contributors_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/contributors","subscribers_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/subscribers","subscription_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/subscription","commits_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/commits{/sha}","git_commits_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/commits{/sha}","comments_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/comments{/number}","issue_comment_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/comments{/number}","contents_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/contents/{+path}","compare_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/merges","archive_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/downloads","issues_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues{/number}","pulls_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls{/number}","milestones_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/milestones{/number}","notifications_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/labels{/name}","releases_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/releases{/id}","deployments_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/deployments","created_at":"2018-05-14T16:02:01Z","updated_at":"2018-05-29T17:08:59Z","pushed_at":"2018-05-30T04:37:45Z","git_url":"git://github.com/chukwuemekachm/Maintenance-Tracker.git","ssh_url":"git@github.com:chukwuemekachm/Maintenance-Tracker.git","clone_url":"https://github.com/chukwuemekachm/Maintenance-Tracker.git","svn_url":"https://github.com/chukwuemekachm/Maintenance-Tracker","homepage":null,"size":10675,"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":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"chukwuemekachm:develop","ref":"develop","sha":"672c2177adc265219c1bbf47f55eb815eecf09f4","user":{"login":"chukwuemekachm","id":33798252,"avatar_url":"https://avatars0.githubusercontent.com/u/33798252?v=4","gravatar_id":"","url":"https://api.github.com/users/chukwuemekachm","html_url":"https://github.com/chukwuemekachm","followers_url":"https://api.github.com/users/chukwuemekachm/followers","following_url":"https://api.github.com/users/chukwuemekachm/following{/other_user}","gists_url":"https://api.github.com/users/chukwuemekachm/gists{/gist_id}","starred_url":"https://api.github.com/users/chukwuemekachm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chukwuemekachm/subscriptions","organizations_url":"https://api.github.com/users/chukwuemekachm/orgs","repos_url":"https://api.github.com/users/chukwuemekachm/repos","events_url":"https://api.github.com/users/chukwuemekachm/events{/privacy}","received_events_url":"https://api.github.com/users/chukwuemekachm/received_events","type":"User","site_admin":false},"repo":{"id":133387421,"name":"Maintenance-Tracker","full_name":"chukwuemekachm/Maintenance-Tracker","owner":{"login":"chukwuemekachm","id":33798252,"avatar_url":"https://avatars0.githubusercontent.com/u/33798252?v=4","gravatar_id":"","url":"https://api.github.com/users/chukwuemekachm","html_url":"https://github.com/chukwuemekachm","followers_url":"https://api.github.com/users/chukwuemekachm/followers","following_url":"https://api.github.com/users/chukwuemekachm/following{/other_user}","gists_url":"https://api.github.com/users/chukwuemekachm/gists{/gist_id}","starred_url":"https://api.github.com/users/chukwuemekachm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chukwuemekachm/subscriptions","organizations_url":"https://api.github.com/users/chukwuemekachm/orgs","repos_url":"https://api.github.com/users/chukwuemekachm/repos","events_url":"https://api.github.com/users/chukwuemekachm/events{/privacy}","received_events_url":"https://api.github.com/users/chukwuemekachm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chukwuemekachm/Maintenance-Tracker","description":"Maintenance Tracker App is an application that provides users with the ability to reach out to operations or repairs department regarding repair or maintenance requests and monitor the status of their request.","fork":false,"url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker","forks_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/forks","keys_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/teams","hooks_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/hooks","issue_events_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/events{/number}","events_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/events","assignees_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/assignees{/user}","branches_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/branches{/branch}","tags_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/tags","blobs_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/refs{/sha}","trees_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/statuses/{sha}","languages_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/languages","stargazers_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/stargazers","contributors_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/contributors","subscribers_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/subscribers","subscription_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/subscription","commits_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/commits{/sha}","git_commits_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/git/commits{/sha}","comments_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/comments{/number}","issue_comment_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/comments{/number}","contents_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/contents/{+path}","compare_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/merges","archive_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/downloads","issues_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues{/number}","pulls_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls{/number}","milestones_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/milestones{/number}","notifications_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/labels{/name}","releases_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/releases{/id}","deployments_url":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/deployments","created_at":"2018-05-14T16:02:01Z","updated_at":"2018-05-29T17:08:59Z","pushed_at":"2018-05-30T04:37:45Z","git_url":"git://github.com/chukwuemekachm/Maintenance-Tracker.git","ssh_url":"git@github.com:chukwuemekachm/Maintenance-Tracker.git","clone_url":"https://github.com/chukwuemekachm/Maintenance-Tracker.git","svn_url":"https://github.com/chukwuemekachm/Maintenance-Tracker","homepage":null,"size":10675,"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":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52"},"html":{"href":"https://github.com/chukwuemekachm/Maintenance-Tracker/pull/52"},"issue":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/52"},"comments":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/issues/52/comments"},"review_comments":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52/comments"},"review_comment":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/pulls/52/commits"},"statuses":{"href":"https://api.github.com/repos/chukwuemekachm/Maintenance-Tracker/statuses/fc5f7d97eaf0ae3724850b0550e43387e883178c"}},"author_association":"OWNER"}}
{"actor":{"display_login":"benfluleck"}}