{"action":"created","comment":{"url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/comments/152010585","pull_request_review_id":77806764,"id":152010585,"diff_hunk":"@@ -0,0 +1,187 @@\n+import {\n+  Shops,\n+  Products,\n+  Orders,\n+  Cart,\n+  Inventory,\n+  Emails,\n+  Accounts,\n+  Logs,\n+  Groups,\n+  Assets,\n+  Packages,\n+  Shipping,\n+  Tags\n+} from \"/lib/collections\";\n+import Reaction  from \"/server/api\";\n+\n+const hasPermission = (user, role) => {\n+  return user.roles[Reaction.getShopId()].includes(role);\n+};\n+\n+/**\n+ * Configure CRUD operation for restful apis\n+ */\n+export default () => {\n+  const Api = new Restivus({\n+    useDefaultAuth: true,\n+    prettyJson: true,\n+    defaultHeaders: {\n+      \"Content-Type\": \"application/json\"\n+    },\n+    version: \"v1\"\n+  });\n+\n+  const getRestfulApisOptions = (nameOfCollection) => {\n+    return {\n+      routeOptions: {\n+        authRequired: true\n+      },\n+\n+      endpoints: {\n+        /**\n+           * Post request\n+           */\n+        post: {\n+          action() {\n+            if (!(hasPermission(this.user, \"admin\") ||\n+               hasPermission(this.user, \"owner\"))) {\n+              return {\n+                status: 403,\n+                success: false,\n+                message: \"You are forbidden to post a collection\"\n+              };\n+            }\n+            if (hasPermission(this.user, \"admin\") ||\n+            hasPermission(this.user, \"owner\")) {\n+              const isPosted = nameOfCollection.insert(this.bodyParams);\n+              if (!isPosted) {\n+                return {\n+                  status: 500,\n+                  success: false,\n+                  message: \"An error occurred on your post request\"\n+                };\n+              }\n+              return {\n+                status: 201,\n+                success: true,\n+                postedData: isPosted\n+              };\n+            }\n+          }\n+        },\n+\n+        /**\n+         * Get request\n+         */\n+        get: {\n+          action() {\n+            if (hasPermission(this.user, \"admin\") ||\n+                  hasPermission(this.user, \"owner\") ||\n+                  hasPermission(this.user, \"guest\")) {\n+              const records = nameOfCollection.findOne(this.urlParams.id);\n+              if (!records) {\n+                return {\n+                  status: 404,\n+                  success: false,\n+                  message: \"Records does not exist\"\n+                };\n+              }\n+              return {\n+                status: 200,\n+                success: true,\n+                records: records\n+              };\n+            }\n+          }\n+        },\n+\n+        /**\n+         * Update request\n+         */\n+        update: {\n+          action() {\n+            if (!(hasPermission(this.user, \"admin\") ||\n+                hasPermission(this.user, \"owner\"))) {\n+              return {\n+                status: 403,\n+                success: false,\n+                message: \"You are forbidden to update a collection\"\n+              };\n+            }\n+            if (hasPermission(this.user, \"admin\") ||\n+             hasPermission(this.user, \"owner\")) {\n+              const isUpdated = nameOfCollection.upsert({ _id: this.urlParams.id }, {\n+                $set: this.bodyParams\n+              });\n+              if (!isUpdated) {\n+                return {\n+                  status: 500,\n+                  success: false,\n+                  message: \"An error occurred on your update request\"\n+                };\n+              }\n+              return {\n+                status: 200,\n+                success: true,\n+                updatedData: isUpdated\n+              };\n+            }\n+          }\n+        },\n+\n+        /**\n+         * Delete Request\n+         */\n+        delete: {\n+          action() {","path":"server/startup/restful-apis.js","position":137,"original_position":137,"commit_id":"df692456e9d072cc3e975d7ad8efe122943060e8","original_commit_id":"df692456e9d072cc3e975d7ad8efe122943060e8","user":{"login":"houndci-bot","id":6697940,"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":"'concise methods' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).","created_at":"2017-11-20T14:51:44Z","updated_at":"2017-11-20T14:51:45Z","html_url":"https://github.com/andela/mont-blanc-rc/pull/2#discussion_r152010585","pull_request_url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/comments/152010585"},"html":{"href":"https://github.com/andela/mont-blanc-rc/pull/2#discussion_r152010585"},"pull_request":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2","id":153648765,"html_url":"https://github.com/andela/mont-blanc-rc/pull/2","diff_url":"https://github.com/andela/mont-blanc-rc/pull/2.diff","patch_url":"https://github.com/andela/mont-blanc-rc/pull/2.patch","issue_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues/2","number":2,"state":"open","locked":false,"title":" #152798767 Make the API endpoints RESTful","user":{"login":"ChidinmaOrajiaku","id":30434146,"avatar_url":"https://avatars3.githubusercontent.com/u/30434146?v=4","gravatar_id":"","url":"https://api.github.com/users/ChidinmaOrajiaku","html_url":"https://github.com/ChidinmaOrajiaku","followers_url":"https://api.github.com/users/ChidinmaOrajiaku/followers","following_url":"https://api.github.com/users/ChidinmaOrajiaku/following{/other_user}","gists_url":"https://api.github.com/users/ChidinmaOrajiaku/gists{/gist_id}","starred_url":"https://api.github.com/users/ChidinmaOrajiaku/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChidinmaOrajiaku/subscriptions","organizations_url":"https://api.github.com/users/ChidinmaOrajiaku/orgs","repos_url":"https://api.github.com/users/ChidinmaOrajiaku/repos","events_url":"https://api.github.com/users/ChidinmaOrajiaku/events{/privacy}","received_events_url":"https://api.github.com/users/ChidinmaOrajiaku/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\nMakes api endpoints restful\r\n\r\n#### Description of Task to be completed?\r\nMakes api endpoints restful so that it can be accessible on different platforms\r\n\r\n#### How should this be manually tested?\r\nURL/api/v1/nameOfCollection\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 #152798767- Make the API endpoints RESTful\r\n\r\n#### Screenshots (if appropriate)\r\n![image](https://user-images.githubusercontent.com/30434146/33024136-94069270-ce0a-11e7-8099-96f8dcd62018.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024143-978112c2-ce0a-11e7-802c-7b5d0663dd28.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024149-9b839dfe-ce0a-11e7-9460-1be8010bd587.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024153-9e58872e-ce0a-11e7-98aa-ae3678620807.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024160-a21561e8-ce0a-11e7-9898-44bc5b4fd865.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024163-a5057870-ce0a-11e7-956f-d2fae654ecad.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024166-a8164aee-ce0a-11e7-8212-7e88fc13976d.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024169-aa88f13c-ce0a-11e7-98c7-81d1ad53d5fd.png)\r\n![image](https://user-images.githubusercontent.com/30434146/33024176-adee9138-ce0a-11e7-8a98-1ec6934642ec.png)\r\n\r\n#### Questions:\r\nNone","created_at":"2017-11-20T14:51:40Z","updated_at":"2017-11-20T14:51:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d32667791546dfc494b7dd33676a5abf20e15903","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2/commits","review_comments_url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2/comments","review_comment_url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues/2/comments","statuses_url":"https://api.github.com/repos/andela/mont-blanc-rc/statuses/df692456e9d072cc3e975d7ad8efe122943060e8","head":{"label":"andela:feature/152798767/restful-api-endpoints","ref":"feature/152798767/restful-api-endpoints","sha":"df692456e9d072cc3e975d7ad8efe122943060e8","user":{"login":"andela","id":4100206,"avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"repo":{"id":110507661,"name":"mont-blanc-rc","full_name":"andela/mont-blanc-rc","owner":{"login":"andela","id":4100206,"avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/andela/mont-blanc-rc","description":null,"fork":false,"url":"https://api.github.com/repos/andela/mont-blanc-rc","forks_url":"https://api.github.com/repos/andela/mont-blanc-rc/forks","keys_url":"https://api.github.com/repos/andela/mont-blanc-rc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela/mont-blanc-rc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela/mont-blanc-rc/teams","hooks_url":"https://api.github.com/repos/andela/mont-blanc-rc/hooks","issue_events_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues/events{/number}","events_url":"https://api.github.com/repos/andela/mont-blanc-rc/events","assignees_url":"https://api.github.com/repos/andela/mont-blanc-rc/assignees{/user}","branches_url":"https://api.github.com/repos/andela/mont-blanc-rc/branches{/branch}","tags_url":"https://api.github.com/repos/andela/mont-blanc-rc/tags","blobs_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela/mont-blanc-rc/statuses/{sha}","languages_url":"https://api.github.com/repos/andela/mont-blanc-rc/languages","stargazers_url":"https://api.github.com/repos/andela/mont-blanc-rc/stargazers","contributors_url":"https://api.github.com/repos/andela/mont-blanc-rc/contributors","subscribers_url":"https://api.github.com/repos/andela/mont-blanc-rc/subscribers","subscription_url":"https://api.github.com/repos/andela/mont-blanc-rc/subscription","commits_url":"https://api.github.com/repos/andela/mont-blanc-rc/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela/mont-blanc-rc/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela/mont-blanc-rc/contents/{+path}","compare_url":"https://api.github.com/repos/andela/mont-blanc-rc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela/mont-blanc-rc/merges","archive_url":"https://api.github.com/repos/andela/mont-blanc-rc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela/mont-blanc-rc/downloads","issues_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues{/number}","pulls_url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls{/number}","milestones_url":"https://api.github.com/repos/andela/mont-blanc-rc/milestones{/number}","notifications_url":"https://api.github.com/repos/andela/mont-blanc-rc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela/mont-blanc-rc/labels{/name}","releases_url":"https://api.github.com/repos/andela/mont-blanc-rc/releases{/id}","deployments_url":"https://api.github.com/repos/andela/mont-blanc-rc/deployments","created_at":"2017-11-13T06:14:22Z","updated_at":"2017-11-13T08:46:46Z","pushed_at":"2017-11-20T14:51:40Z","git_url":"git://github.com/andela/mont-blanc-rc.git","ssh_url":"git@github.com:andela/mont-blanc-rc.git","clone_url":"https://github.com/andela/mont-blanc-rc.git","svn_url":"https://github.com/andela/mont-blanc-rc","homepage":null,"size":38013,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"staging"}},"base":{"label":"andela:staging","ref":"staging","sha":"4eb2b6facc9349a6d5e956ab93ac8308f774509e","user":{"login":"andela","id":4100206,"avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"repo":{"id":110507661,"name":"mont-blanc-rc","full_name":"andela/mont-blanc-rc","owner":{"login":"andela","id":4100206,"avatar_url":"https://avatars2.githubusercontent.com/u/4100206?v=4","gravatar_id":"","url":"https://api.github.com/users/andela","html_url":"https://github.com/andela","followers_url":"https://api.github.com/users/andela/followers","following_url":"https://api.github.com/users/andela/following{/other_user}","gists_url":"https://api.github.com/users/andela/gists{/gist_id}","starred_url":"https://api.github.com/users/andela/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela/subscriptions","organizations_url":"https://api.github.com/users/andela/orgs","repos_url":"https://api.github.com/users/andela/repos","events_url":"https://api.github.com/users/andela/events{/privacy}","received_events_url":"https://api.github.com/users/andela/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/andela/mont-blanc-rc","description":null,"fork":false,"url":"https://api.github.com/repos/andela/mont-blanc-rc","forks_url":"https://api.github.com/repos/andela/mont-blanc-rc/forks","keys_url":"https://api.github.com/repos/andela/mont-blanc-rc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela/mont-blanc-rc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela/mont-blanc-rc/teams","hooks_url":"https://api.github.com/repos/andela/mont-blanc-rc/hooks","issue_events_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues/events{/number}","events_url":"https://api.github.com/repos/andela/mont-blanc-rc/events","assignees_url":"https://api.github.com/repos/andela/mont-blanc-rc/assignees{/user}","branches_url":"https://api.github.com/repos/andela/mont-blanc-rc/branches{/branch}","tags_url":"https://api.github.com/repos/andela/mont-blanc-rc/tags","blobs_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela/mont-blanc-rc/statuses/{sha}","languages_url":"https://api.github.com/repos/andela/mont-blanc-rc/languages","stargazers_url":"https://api.github.com/repos/andela/mont-blanc-rc/stargazers","contributors_url":"https://api.github.com/repos/andela/mont-blanc-rc/contributors","subscribers_url":"https://api.github.com/repos/andela/mont-blanc-rc/subscribers","subscription_url":"https://api.github.com/repos/andela/mont-blanc-rc/subscription","commits_url":"https://api.github.com/repos/andela/mont-blanc-rc/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela/mont-blanc-rc/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela/mont-blanc-rc/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela/mont-blanc-rc/contents/{+path}","compare_url":"https://api.github.com/repos/andela/mont-blanc-rc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela/mont-blanc-rc/merges","archive_url":"https://api.github.com/repos/andela/mont-blanc-rc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela/mont-blanc-rc/downloads","issues_url":"https://api.github.com/repos/andela/mont-blanc-rc/issues{/number}","pulls_url":"https://api.github.com/repos/andela/mont-blanc-rc/pulls{/number}","milestones_url":"https://api.github.com/repos/andela/mont-blanc-rc/milestones{/number}","notifications_url":"https://api.github.com/repos/andela/mont-blanc-rc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela/mont-blanc-rc/labels{/name}","releases_url":"https://api.github.com/repos/andela/mont-blanc-rc/releases{/id}","deployments_url":"https://api.github.com/repos/andela/mont-blanc-rc/deployments","created_at":"2017-11-13T06:14:22Z","updated_at":"2017-11-13T08:46:46Z","pushed_at":"2017-11-20T14:51:40Z","git_url":"git://github.com/andela/mont-blanc-rc.git","ssh_url":"git@github.com:andela/mont-blanc-rc.git","clone_url":"https://github.com/andela/mont-blanc-rc.git","svn_url":"https://github.com/andela/mont-blanc-rc","homepage":null,"size":38013,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2"},"html":{"href":"https://github.com/andela/mont-blanc-rc/pull/2"},"issue":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/issues/2"},"comments":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/andela/mont-blanc-rc/statuses/df692456e9d072cc3e975d7ad8efe122943060e8"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"houndci-bot"}}