{"action":"created","comment":{"url":"https://api.github.com/repos/kitchensupport/api/pulls/comments/44372071","id":44372071,"diff_hunk":"@@ -0,0 +1,79 @@\n+import express from 'express';\n+import authorize from '../middleware/auth';\n+import {Collection as RecipeCollection} from '../models/recipe';\n+import {Collection as UserRecipeCollection, makeRelationship} from '../models/user-recipe';\n+\n+const router = express();\n+\n+export function routes() {\n+    return router;\n+};\n+\n+/* ********* route initialization ********* */\n+\n+router.use(authorize());\n+const completed = router.route('/completed');\n+\n+completed.get((req, res, next) => {\n+    UserRecipeCollection.query((query) => {\n+        query.where({\n+            user_id: req.user.id,\n+            made: true\n+        }).limit(req.query.limit || 30)\n+        .offset(req.query.offset || 0)\n+        .orderBy('id');\n+    }).fetch({withRelated: ['recipe']}).then((urs) => {\n+        res.status(200).send(new RecipeCollection(urs.map((ur) => {\n+            return ur.related('recipe');\n+        })).toJSON({\n+            status: 'success'\n+        }));\n+    }).catch(() => {\n+        res.status(403).send({\n+            status: 'failure',\n+            error: 'Unable to retrieve completed recipes'\n+        });\n+\n+        next(new Error(`Unable to load completed recipes for user ${req.user.id}`));\n+    });\n+});\n+\n+completed.post((req, res, next) => {\n+    makeRelationship({\n+        userId: req.user.id,\n+        recipeId: req.body.recipe_id,\n+        action: 'made',\n+        value: true\n+    }).then(() => {\n+        res.status(200).send({\n+            status: 'success'\n+        });\n+    }).catch(() => {\n+        res.status(403).send({\n+            status: 'failure',\n+            error: 'Can not favorite this recipe'\n+        });\n+\n+        next(new Error(`User ${req.user.id} can not favorite recipe ${req.body.recipe_id}`));\n+    });\n+});\n+\n+completed.delete((req, res, next) => {\n+    makeRelationship({\n+        userId: req.user.id,\n+        recipeId: req.body.recipe_id,\n+        action: 'made',\n+        value: false\n+    }).then(() => {\n+        res.status(200).send({\n+            status: 'success'\n+        });\n+    }).catch(() => {\n+        res.status(403).send({\n+            status: 'failure',\n+            error: 'Can not favorite this recipe'\n+        });\n+\n+        next(new Error(`User ${req.user.id} can not delete favorited recipe ${req.body.recipe_id}`));","path":"src/controllers/completed.js","position":77,"original_position":77,"commit_id":"35d5bb566e145f073adb340ea660a995a406241f","original_commit_id":"35d5bb566e145f073adb340ea660a995a406241f","user":{"login":"garrickb","id":3732560,"avatar_url":"https://avatars.githubusercontent.com/u/3732560?v=3","gravatar_id":"","url":"https://api.github.com/users/garrickb","html_url":"https://github.com/garrickb","followers_url":"https://api.github.com/users/garrickb/followers","following_url":"https://api.github.com/users/garrickb/following{/other_user}","gists_url":"https://api.github.com/users/garrickb/gists{/gist_id}","starred_url":"https://api.github.com/users/garrickb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garrickb/subscriptions","organizations_url":"https://api.github.com/users/garrickb/orgs","repos_url":"https://api.github.com/users/garrickb/repos","events_url":"https://api.github.com/users/garrickb/events{/privacy}","received_events_url":"https://api.github.com/users/garrickb/received_events","type":"User","site_admin":false},"body":"what","created_at":"2015-11-10T05:45:58Z","updated_at":"2015-11-10T05:45:58Z","html_url":"https://github.com/kitchensupport/api/pull/25#discussion_r44372071","pull_request_url":"https://api.github.com/repos/kitchensupport/api/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/kitchensupport/api/pulls/comments/44372071"},"html":{"href":"https://github.com/kitchensupport/api/pull/25#discussion_r44372071"},"pull_request":{"href":"https://api.github.com/repos/kitchensupport/api/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/kitchensupport/api/pulls/25","id":50215157,"html_url":"https://github.com/kitchensupport/api/pull/25","diff_url":"https://github.com/kitchensupport/api/pull/25.diff","patch_url":"https://github.com/kitchensupport/api/pull/25.patch","issue_url":"https://api.github.com/repos/kitchensupport/api/issues/25","number":25,"state":"open","locked":false,"title":"Updated \"liking\", added \"favoriting\" and \"completing\"","user":{"login":"jackhorton","id":4370013,"avatar_url":"https://avatars.githubusercontent.com/u/4370013?v=3","gravatar_id":"","url":"https://api.github.com/users/jackhorton","html_url":"https://github.com/jackhorton","followers_url":"https://api.github.com/users/jackhorton/followers","following_url":"https://api.github.com/users/jackhorton/following{/other_user}","gists_url":"https://api.github.com/users/jackhorton/gists{/gist_id}","starred_url":"https://api.github.com/users/jackhorton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackhorton/subscriptions","organizations_url":"https://api.github.com/users/jackhorton/orgs","repos_url":"https://api.github.com/users/jackhorton/repos","events_url":"https://api.github.com/users/jackhorton/events{/privacy}","received_events_url":"https://api.github.com/users/jackhorton/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-10T05:14:27Z","updated_at":"2015-11-10T05:45:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1563511ff120fc76dfd9b516b3672706f38e5236","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kitchensupport/api/pulls/25/commits","review_comments_url":"https://api.github.com/repos/kitchensupport/api/pulls/25/comments","review_comment_url":"https://api.github.com/repos/kitchensupport/api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kitchensupport/api/issues/25/comments","statuses_url":"https://api.github.com/repos/kitchensupport/api/statuses/35d5bb566e145f073adb340ea660a995a406241f","head":{"label":"jackhorton:master","ref":"master","sha":"35d5bb566e145f073adb340ea660a995a406241f","user":{"login":"jackhorton","id":4370013,"avatar_url":"https://avatars.githubusercontent.com/u/4370013?v=3","gravatar_id":"","url":"https://api.github.com/users/jackhorton","html_url":"https://github.com/jackhorton","followers_url":"https://api.github.com/users/jackhorton/followers","following_url":"https://api.github.com/users/jackhorton/following{/other_user}","gists_url":"https://api.github.com/users/jackhorton/gists{/gist_id}","starred_url":"https://api.github.com/users/jackhorton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackhorton/subscriptions","organizations_url":"https://api.github.com/users/jackhorton/orgs","repos_url":"https://api.github.com/users/jackhorton/repos","events_url":"https://api.github.com/users/jackhorton/events{/privacy}","received_events_url":"https://api.github.com/users/jackhorton/received_events","type":"User","site_admin":false},"repo":{"id":43475797,"name":"api","full_name":"jackhorton/api","owner":{"login":"jackhorton","id":4370013,"avatar_url":"https://avatars.githubusercontent.com/u/4370013?v=3","gravatar_id":"","url":"https://api.github.com/users/jackhorton","html_url":"https://github.com/jackhorton","followers_url":"https://api.github.com/users/jackhorton/followers","following_url":"https://api.github.com/users/jackhorton/following{/other_user}","gists_url":"https://api.github.com/users/jackhorton/gists{/gist_id}","starred_url":"https://api.github.com/users/jackhorton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackhorton/subscriptions","organizations_url":"https://api.github.com/users/jackhorton/orgs","repos_url":"https://api.github.com/users/jackhorton/repos","events_url":"https://api.github.com/users/jackhorton/events{/privacy}","received_events_url":"https://api.github.com/users/jackhorton/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jackhorton/api","description":"Backend API for Kitchen Support","fork":true,"url":"https://api.github.com/repos/jackhorton/api","forks_url":"https://api.github.com/repos/jackhorton/api/forks","keys_url":"https://api.github.com/repos/jackhorton/api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jackhorton/api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jackhorton/api/teams","hooks_url":"https://api.github.com/repos/jackhorton/api/hooks","issue_events_url":"https://api.github.com/repos/jackhorton/api/issues/events{/number}","events_url":"https://api.github.com/repos/jackhorton/api/events","assignees_url":"https://api.github.com/repos/jackhorton/api/assignees{/user}","branches_url":"https://api.github.com/repos/jackhorton/api/branches{/branch}","tags_url":"https://api.github.com/repos/jackhorton/api/tags","blobs_url":"https://api.github.com/repos/jackhorton/api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jackhorton/api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jackhorton/api/git/refs{/sha}","trees_url":"https://api.github.com/repos/jackhorton/api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jackhorton/api/statuses/{sha}","languages_url":"https://api.github.com/repos/jackhorton/api/languages","stargazers_url":"https://api.github.com/repos/jackhorton/api/stargazers","contributors_url":"https://api.github.com/repos/jackhorton/api/contributors","subscribers_url":"https://api.github.com/repos/jackhorton/api/subscribers","subscription_url":"https://api.github.com/repos/jackhorton/api/subscription","commits_url":"https://api.github.com/repos/jackhorton/api/commits{/sha}","git_commits_url":"https://api.github.com/repos/jackhorton/api/git/commits{/sha}","comments_url":"https://api.github.com/repos/jackhorton/api/comments{/number}","issue_comment_url":"https://api.github.com/repos/jackhorton/api/issues/comments{/number}","contents_url":"https://api.github.com/repos/jackhorton/api/contents/{+path}","compare_url":"https://api.github.com/repos/jackhorton/api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jackhorton/api/merges","archive_url":"https://api.github.com/repos/jackhorton/api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jackhorton/api/downloads","issues_url":"https://api.github.com/repos/jackhorton/api/issues{/number}","pulls_url":"https://api.github.com/repos/jackhorton/api/pulls{/number}","milestones_url":"https://api.github.com/repos/jackhorton/api/milestones{/number}","notifications_url":"https://api.github.com/repos/jackhorton/api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jackhorton/api/labels{/name}","releases_url":"https://api.github.com/repos/jackhorton/api/releases{/id}","created_at":"2015-10-01T03:07:46Z","updated_at":"2015-10-03T18:51:29Z","pushed_at":"2015-11-10T05:12:05Z","git_url":"git://github.com/jackhorton/api.git","ssh_url":"git@github.com:jackhorton/api.git","clone_url":"https://github.com/jackhorton/api.git","svn_url":"https://github.com/jackhorton/api","homepage":null,"size":200,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"kitchensupport:master","ref":"master","sha":"254a12ac2a1d30d1384d9e02a40c9e5eda2a8932","user":{"login":"kitchensupport","id":14228151,"avatar_url":"https://avatars.githubusercontent.com/u/14228151?v=3","gravatar_id":"","url":"https://api.github.com/users/kitchensupport","html_url":"https://github.com/kitchensupport","followers_url":"https://api.github.com/users/kitchensupport/followers","following_url":"https://api.github.com/users/kitchensupport/following{/other_user}","gists_url":"https://api.github.com/users/kitchensupport/gists{/gist_id}","starred_url":"https://api.github.com/users/kitchensupport/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitchensupport/subscriptions","organizations_url":"https://api.github.com/users/kitchensupport/orgs","repos_url":"https://api.github.com/users/kitchensupport/repos","events_url":"https://api.github.com/users/kitchensupport/events{/privacy}","received_events_url":"https://api.github.com/users/kitchensupport/received_events","type":"Organization","site_admin":false},"repo":{"id":42369865,"name":"api","full_name":"kitchensupport/api","owner":{"login":"kitchensupport","id":14228151,"avatar_url":"https://avatars.githubusercontent.com/u/14228151?v=3","gravatar_id":"","url":"https://api.github.com/users/kitchensupport","html_url":"https://github.com/kitchensupport","followers_url":"https://api.github.com/users/kitchensupport/followers","following_url":"https://api.github.com/users/kitchensupport/following{/other_user}","gists_url":"https://api.github.com/users/kitchensupport/gists{/gist_id}","starred_url":"https://api.github.com/users/kitchensupport/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitchensupport/subscriptions","organizations_url":"https://api.github.com/users/kitchensupport/orgs","repos_url":"https://api.github.com/users/kitchensupport/repos","events_url":"https://api.github.com/users/kitchensupport/events{/privacy}","received_events_url":"https://api.github.com/users/kitchensupport/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kitchensupport/api","description":"Backend API for Kitchen Support","fork":false,"url":"https://api.github.com/repos/kitchensupport/api","forks_url":"https://api.github.com/repos/kitchensupport/api/forks","keys_url":"https://api.github.com/repos/kitchensupport/api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kitchensupport/api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kitchensupport/api/teams","hooks_url":"https://api.github.com/repos/kitchensupport/api/hooks","issue_events_url":"https://api.github.com/repos/kitchensupport/api/issues/events{/number}","events_url":"https://api.github.com/repos/kitchensupport/api/events","assignees_url":"https://api.github.com/repos/kitchensupport/api/assignees{/user}","branches_url":"https://api.github.com/repos/kitchensupport/api/branches{/branch}","tags_url":"https://api.github.com/repos/kitchensupport/api/tags","blobs_url":"https://api.github.com/repos/kitchensupport/api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kitchensupport/api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kitchensupport/api/git/refs{/sha}","trees_url":"https://api.github.com/repos/kitchensupport/api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kitchensupport/api/statuses/{sha}","languages_url":"https://api.github.com/repos/kitchensupport/api/languages","stargazers_url":"https://api.github.com/repos/kitchensupport/api/stargazers","contributors_url":"https://api.github.com/repos/kitchensupport/api/contributors","subscribers_url":"https://api.github.com/repos/kitchensupport/api/subscribers","subscription_url":"https://api.github.com/repos/kitchensupport/api/subscription","commits_url":"https://api.github.com/repos/kitchensupport/api/commits{/sha}","git_commits_url":"https://api.github.com/repos/kitchensupport/api/git/commits{/sha}","comments_url":"https://api.github.com/repos/kitchensupport/api/comments{/number}","issue_comment_url":"https://api.github.com/repos/kitchensupport/api/issues/comments{/number}","contents_url":"https://api.github.com/repos/kitchensupport/api/contents/{+path}","compare_url":"https://api.github.com/repos/kitchensupport/api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kitchensupport/api/merges","archive_url":"https://api.github.com/repos/kitchensupport/api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kitchensupport/api/downloads","issues_url":"https://api.github.com/repos/kitchensupport/api/issues{/number}","pulls_url":"https://api.github.com/repos/kitchensupport/api/pulls{/number}","milestones_url":"https://api.github.com/repos/kitchensupport/api/milestones{/number}","notifications_url":"https://api.github.com/repos/kitchensupport/api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kitchensupport/api/labels{/name}","releases_url":"https://api.github.com/repos/kitchensupport/api/releases{/id}","created_at":"2015-09-12T19:20:04Z","updated_at":"2015-10-31T20:52:25Z","pushed_at":"2015-11-10T05:14:27Z","git_url":"git://github.com/kitchensupport/api.git","ssh_url":"git@github.com:kitchensupport/api.git","clone_url":"https://github.com/kitchensupport/api.git","svn_url":"https://github.com/kitchensupport/api","homepage":null,"size":411,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kitchensupport/api/pulls/25"},"html":{"href":"https://github.com/kitchensupport/api/pull/25"},"issue":{"href":"https://api.github.com/repos/kitchensupport/api/issues/25"},"comments":{"href":"https://api.github.com/repos/kitchensupport/api/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/kitchensupport/api/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/kitchensupport/api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kitchensupport/api/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/kitchensupport/api/statuses/35d5bb566e145f073adb340ea660a995a406241f"}}}}