{"action":"created","comment":{"url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/comments/25141272","id":25141272,"diff_hunk":"@@ -0,0 +1,159 @@\n+// Models.\n+var Ingredient = require('../models/ingredient');\n+var Order = require('../models/order');\n+\n+\n+// Queries for all ingredients and sends them back to the client.\n+var sendIngredients = function (res) {\n+\tIngredient.find()\n+\t\t.sort({name: 1})\n+\t\t.exec(function (err, ingredients) {\n+\t\t\tres.render(\"partials/ingredient-list\", {\n+\t\t\t\tlayout: false,\n+\t\t\t\tingredients: ingredients\n+\t\t\t})\n+\t\t});\n+}\n+\n+// Similar to sendIngredients. Sends ingredients rendered as order items.\n+var sendOrderItems = function (res) {\n+\tIngredient.find()\n+\t\t.sort({name: 1})\n+\t\t.exec(function (err, ingredients) {\n+\t\t\tres.render(\"partials/ingredient-order-list\", {\n+\t\t\t\tlayout: false,\n+\t\t\t\tingredients: ingredients\n+\t\t\t})\n+\t\t});\n+}\n+\n+// Similar to sendIngredients. Sends ingredients rendered as order items.\n+var sendKitchenItems = function (res) {\n+\tOrder.find()\n+\t\t.sort({name: 1})\n+\t\t.exec(function (err, orders) {\n+\t\t\tres.render(\"partials/kitchen-list\", {\n+\t\t\t\tlayout: false,\n+\t\t\t\torders: orders\n+\t\t\t})\n+\t\t});\n+}\n+\n+// Save the ingredients into the database.\n+var saveIngredient = function (res, newIngredient) {\n+\tnewIngredient.save(function (err) {\n+\t\tif (err) console.log(\"Error: \" + err);\n+\t\tsendIngredients(res);\n+\t});\n+}\n+\n+// Save the order and return a success statement to client.\n+var saveOrder = function (res, personName, orderItems) {\n+\tvar newOrder = new Order({\n+\t\tpersonName: personName,\n+\t\torderItems: orderItems\n+\t});\n+\n+\tnewOrder.save(function (err) {\n+\t\tif (err) console.log(\"Error: \" + err);\n+\t\tres.render(\"partials/success-alert\", {\n+\t\t\tlayout: false\n+\t\t}, function (err,html){\n+\t\t\tres.send(html);\n+\t\t});\n+\t})\n+}\n+\n+module.exports = {\n+\t\n+\tgetHome: function (req, res){\n+\t\tres.render(\"base\");\n+\t},\n+\n+\tgetIngredients: function (req, res){\n+\t\t\n+\t\t// Check if the request is AJAX.\n+\t\tvar is_ajax_request = req.xhr;\n+\t\tif (is_ajax_request) {\n+\t\t\tsendIngredients(res);\n+\t\t} else {\n+\t\t\tres.render(\"ingredients\");\n+\t\t}\n+\t},\n+\n+\tpostIngredients: function (req, res){\n+\t\t\n+\t\t// Find ingredient. If it doesn't exist, create a new ingredient.\n+\t\tIngredient.findOne({_id: req.body.id}, function (err, ingredient){\n+\t\t  if (err) console.log(\"Error: \" + err);\n+\t\t  if (ingredient) {\n+\t\t  \tingredient.name = req.body.name;\n+\t  \t\tingredient.price = req.body.price;\n+\t\t  } else {\n+\t\t  \tvar ingredient = new Ingredient({\n+\t\t  \t\tname: req.body.name,\n+\t\t\t\t\tprice: req.body.price,\n+\t\t\t\t\tinstock: \"yes\"\n+\t\t  \t});\n+\t\t  }\n+\t  \tsaveIngredient(res, ingredient);\n+\t\t});\n+\t},\n+\n+\t// Change the state of the ingredient from being in and out of stock.\n+\ttoggleIngredient: function (req, res){\n+\t\tIngredient.findOne({ _id: req.body.id }, function (err, ingredient){\n+\t\t\tif (err) console.log(\"Error: \" + err);\n+\t\t\tif (ingredient) {\n+\t\t\t\tingredient.instock = !ingredient.instock;\n+\t\t\t\tsaveIngredient(res, ingredient);\n+\t\t\t} \n+\t\t});\n+\t},\n+\n+\tgetOrder: function (req, res){\n+\t\t// Check if the request is AJAX.\n+\t\tvar is_ajax_request = req.xhr;\n+\t\tif (is_ajax_request) {\n+\t\t\tsendOrderItems(res);\n+\t\t} else {\n+\t\t\tres.render(\"order-page\");\n+\t\t}\n+\t},\n+\n+\tpostOrder: function (req, res){\n+\t\tvar personName = req.body.personName;\n+\n+\t\t// To prevent orderIDs from not becoming an array.\n+\t\tvar orderIDs = [];\n+\t\torderIDs = orderIDs.concat(req.body['orderIDs[]']);\n+\n+\t\t// Find all ingredients that match the ID of the order submitted.\n+\t\tIngredient.find({_id:{$in: orderIDs}}, function (err, ingredients){\n+\t\t\tif (err) console.log(\"Error: \" + err);\n+\n+\t\t\t// Save this order to the database.\n+\t\t\tsaveOrder(res, personName, ingredients);\n+\t\t});\n+\t},\n+\n+\tdeleteOrder: function (req, res){\n+\t\tvar chosenOrderID = req.body.orderID;\n+\t\tOrder.find({_id: chosenOrderID})\n+\t\t\t.remove()\n+\t\t\t.exec( function (err) {\n+\t\t\t\tif (err) console.log(\"Err: \" + err);","path":"classes/class04/JessicasBurgers/routes/burger-router.js","position":145,"original_position":145,"commit_id":"4c4d37d2f6f41ee7878f1c21e73c9226542242d3","original_commit_id":"4c4d37d2f6f41ee7878f1c21e73c9226542242d3","user":{"login":"EvanSimpson","id":1757661,"avatar_url":"https://avatars.githubusercontent.com/u/1757661?v=3","gravatar_id":"","url":"https://api.github.com/users/EvanSimpson","html_url":"https://github.com/EvanSimpson","followers_url":"https://api.github.com/users/EvanSimpson/followers","following_url":"https://api.github.com/users/EvanSimpson/following{/other_user}","gists_url":"https://api.github.com/users/EvanSimpson/gists{/gist_id}","starred_url":"https://api.github.com/users/EvanSimpson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvanSimpson/subscriptions","organizations_url":"https://api.github.com/users/EvanSimpson/orgs","repos_url":"https://api.github.com/users/EvanSimpson/repos","events_url":"https://api.github.com/users/EvanSimpson/events{/privacy}","received_events_url":"https://api.github.com/users/EvanSimpson/received_events","type":"User","site_admin":false},"body":"It's cool that you're checking for errors. It'd be even cooler if you were to handle them by doing something different when one comes up.","created_at":"2015-02-23T02:17:57Z","updated_at":"2015-02-23T02:17:57Z","html_url":"https://github.com/hdavidzhu/olinjs/pull/3#discussion_r25141272","pull_request_url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/comments/25141272"},"html":{"href":"https://github.com/hdavidzhu/olinjs/pull/3#discussion_r25141272"},"pull_request":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3","id":29049212,"html_url":"https://github.com/hdavidzhu/olinjs/pull/3","diff_url":"https://github.com/hdavidzhu/olinjs/pull/3.diff","patch_url":"https://github.com/hdavidzhu/olinjs/pull/3.patch","issue_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues/3","number":3,"state":"open","locked":false,"title":"Homework 4","user":{"login":"hdavidzhu","id":3756871,"avatar_url":"https://avatars.githubusercontent.com/u/3756871?v=3","gravatar_id":"","url":"https://api.github.com/users/hdavidzhu","html_url":"https://github.com/hdavidzhu","followers_url":"https://api.github.com/users/hdavidzhu/followers","following_url":"https://api.github.com/users/hdavidzhu/following{/other_user}","gists_url":"https://api.github.com/users/hdavidzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/hdavidzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hdavidzhu/subscriptions","organizations_url":"https://api.github.com/users/hdavidzhu/orgs","repos_url":"https://api.github.com/users/hdavidzhu/repos","events_url":"https://api.github.com/users/hdavidzhu/events{/privacy}","received_events_url":"https://api.github.com/users/hdavidzhu/received_events","type":"User","site_admin":false},"body":"Oh my als;fj;laksdjf;lasjdf;lksajdf;l why is this so difficult.","created_at":"2015-02-10T22:01:55Z","updated_at":"2015-02-23T02:17:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"28699e83d26f654de97dbc1064cb886a60c920d6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3/commits","review_comments_url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3/comments","review_comment_url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues/3/comments","statuses_url":"https://api.github.com/repos/hdavidzhu/olinjs/statuses/4c4d37d2f6f41ee7878f1c21e73c9226542242d3","head":{"label":"hdavidzhu:homework4","ref":"homework4","sha":"4c4d37d2f6f41ee7878f1c21e73c9226542242d3","user":{"login":"hdavidzhu","id":3756871,"avatar_url":"https://avatars.githubusercontent.com/u/3756871?v=3","gravatar_id":"","url":"https://api.github.com/users/hdavidzhu","html_url":"https://github.com/hdavidzhu","followers_url":"https://api.github.com/users/hdavidzhu/followers","following_url":"https://api.github.com/users/hdavidzhu/following{/other_user}","gists_url":"https://api.github.com/users/hdavidzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/hdavidzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hdavidzhu/subscriptions","organizations_url":"https://api.github.com/users/hdavidzhu/orgs","repos_url":"https://api.github.com/users/hdavidzhu/repos","events_url":"https://api.github.com/users/hdavidzhu/events{/privacy}","received_events_url":"https://api.github.com/users/hdavidzhu/received_events","type":"User","site_admin":false},"repo":{"id":29231448,"name":"olinjs","full_name":"hdavidzhu/olinjs","owner":{"login":"hdavidzhu","id":3756871,"avatar_url":"https://avatars.githubusercontent.com/u/3756871?v=3","gravatar_id":"","url":"https://api.github.com/users/hdavidzhu","html_url":"https://github.com/hdavidzhu","followers_url":"https://api.github.com/users/hdavidzhu/followers","following_url":"https://api.github.com/users/hdavidzhu/following{/other_user}","gists_url":"https://api.github.com/users/hdavidzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/hdavidzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hdavidzhu/subscriptions","organizations_url":"https://api.github.com/users/hdavidzhu/orgs","repos_url":"https://api.github.com/users/hdavidzhu/repos","events_url":"https://api.github.com/users/hdavidzhu/events{/privacy}","received_events_url":"https://api.github.com/users/hdavidzhu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hdavidzhu/olinjs","description":"The second offering of Olin.js in the spring of 2015","fork":true,"url":"https://api.github.com/repos/hdavidzhu/olinjs","forks_url":"https://api.github.com/repos/hdavidzhu/olinjs/forks","keys_url":"https://api.github.com/repos/hdavidzhu/olinjs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hdavidzhu/olinjs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hdavidzhu/olinjs/teams","hooks_url":"https://api.github.com/repos/hdavidzhu/olinjs/hooks","issue_events_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues/events{/number}","events_url":"https://api.github.com/repos/hdavidzhu/olinjs/events","assignees_url":"https://api.github.com/repos/hdavidzhu/olinjs/assignees{/user}","branches_url":"https://api.github.com/repos/hdavidzhu/olinjs/branches{/branch}","tags_url":"https://api.github.com/repos/hdavidzhu/olinjs/tags","blobs_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/refs{/sha}","trees_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hdavidzhu/olinjs/statuses/{sha}","languages_url":"https://api.github.com/repos/hdavidzhu/olinjs/languages","stargazers_url":"https://api.github.com/repos/hdavidzhu/olinjs/stargazers","contributors_url":"https://api.github.com/repos/hdavidzhu/olinjs/contributors","subscribers_url":"https://api.github.com/repos/hdavidzhu/olinjs/subscribers","subscription_url":"https://api.github.com/repos/hdavidzhu/olinjs/subscription","commits_url":"https://api.github.com/repos/hdavidzhu/olinjs/commits{/sha}","git_commits_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/commits{/sha}","comments_url":"https://api.github.com/repos/hdavidzhu/olinjs/comments{/number}","issue_comment_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues/comments{/number}","contents_url":"https://api.github.com/repos/hdavidzhu/olinjs/contents/{+path}","compare_url":"https://api.github.com/repos/hdavidzhu/olinjs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hdavidzhu/olinjs/merges","archive_url":"https://api.github.com/repos/hdavidzhu/olinjs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hdavidzhu/olinjs/downloads","issues_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues{/number}","pulls_url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls{/number}","milestones_url":"https://api.github.com/repos/hdavidzhu/olinjs/milestones{/number}","notifications_url":"https://api.github.com/repos/hdavidzhu/olinjs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hdavidzhu/olinjs/labels{/name}","releases_url":"https://api.github.com/repos/hdavidzhu/olinjs/releases{/id}","created_at":"2015-01-14T06:53:27Z","updated_at":"2015-02-17T16:38:08Z","pushed_at":"2015-02-18T03:13:52Z","git_url":"git://github.com/hdavidzhu/olinjs.git","ssh_url":"git@github.com:hdavidzhu/olinjs.git","clone_url":"https://github.com/hdavidzhu/olinjs.git","svn_url":"https://github.com/hdavidzhu/olinjs","homepage":null,"size":3927,"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":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"hdavidzhu:master","ref":"master","sha":"63642b7867cc382decf972669da7634d5df6df94","user":{"login":"hdavidzhu","id":3756871,"avatar_url":"https://avatars.githubusercontent.com/u/3756871?v=3","gravatar_id":"","url":"https://api.github.com/users/hdavidzhu","html_url":"https://github.com/hdavidzhu","followers_url":"https://api.github.com/users/hdavidzhu/followers","following_url":"https://api.github.com/users/hdavidzhu/following{/other_user}","gists_url":"https://api.github.com/users/hdavidzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/hdavidzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hdavidzhu/subscriptions","organizations_url":"https://api.github.com/users/hdavidzhu/orgs","repos_url":"https://api.github.com/users/hdavidzhu/repos","events_url":"https://api.github.com/users/hdavidzhu/events{/privacy}","received_events_url":"https://api.github.com/users/hdavidzhu/received_events","type":"User","site_admin":false},"repo":{"id":29231448,"name":"olinjs","full_name":"hdavidzhu/olinjs","owner":{"login":"hdavidzhu","id":3756871,"avatar_url":"https://avatars.githubusercontent.com/u/3756871?v=3","gravatar_id":"","url":"https://api.github.com/users/hdavidzhu","html_url":"https://github.com/hdavidzhu","followers_url":"https://api.github.com/users/hdavidzhu/followers","following_url":"https://api.github.com/users/hdavidzhu/following{/other_user}","gists_url":"https://api.github.com/users/hdavidzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/hdavidzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hdavidzhu/subscriptions","organizations_url":"https://api.github.com/users/hdavidzhu/orgs","repos_url":"https://api.github.com/users/hdavidzhu/repos","events_url":"https://api.github.com/users/hdavidzhu/events{/privacy}","received_events_url":"https://api.github.com/users/hdavidzhu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hdavidzhu/olinjs","description":"The second offering of Olin.js in the spring of 2015","fork":true,"url":"https://api.github.com/repos/hdavidzhu/olinjs","forks_url":"https://api.github.com/repos/hdavidzhu/olinjs/forks","keys_url":"https://api.github.com/repos/hdavidzhu/olinjs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hdavidzhu/olinjs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hdavidzhu/olinjs/teams","hooks_url":"https://api.github.com/repos/hdavidzhu/olinjs/hooks","issue_events_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues/events{/number}","events_url":"https://api.github.com/repos/hdavidzhu/olinjs/events","assignees_url":"https://api.github.com/repos/hdavidzhu/olinjs/assignees{/user}","branches_url":"https://api.github.com/repos/hdavidzhu/olinjs/branches{/branch}","tags_url":"https://api.github.com/repos/hdavidzhu/olinjs/tags","blobs_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/refs{/sha}","trees_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hdavidzhu/olinjs/statuses/{sha}","languages_url":"https://api.github.com/repos/hdavidzhu/olinjs/languages","stargazers_url":"https://api.github.com/repos/hdavidzhu/olinjs/stargazers","contributors_url":"https://api.github.com/repos/hdavidzhu/olinjs/contributors","subscribers_url":"https://api.github.com/repos/hdavidzhu/olinjs/subscribers","subscription_url":"https://api.github.com/repos/hdavidzhu/olinjs/subscription","commits_url":"https://api.github.com/repos/hdavidzhu/olinjs/commits{/sha}","git_commits_url":"https://api.github.com/repos/hdavidzhu/olinjs/git/commits{/sha}","comments_url":"https://api.github.com/repos/hdavidzhu/olinjs/comments{/number}","issue_comment_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues/comments{/number}","contents_url":"https://api.github.com/repos/hdavidzhu/olinjs/contents/{+path}","compare_url":"https://api.github.com/repos/hdavidzhu/olinjs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hdavidzhu/olinjs/merges","archive_url":"https://api.github.com/repos/hdavidzhu/olinjs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hdavidzhu/olinjs/downloads","issues_url":"https://api.github.com/repos/hdavidzhu/olinjs/issues{/number}","pulls_url":"https://api.github.com/repos/hdavidzhu/olinjs/pulls{/number}","milestones_url":"https://api.github.com/repos/hdavidzhu/olinjs/milestones{/number}","notifications_url":"https://api.github.com/repos/hdavidzhu/olinjs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hdavidzhu/olinjs/labels{/name}","releases_url":"https://api.github.com/repos/hdavidzhu/olinjs/releases{/id}","created_at":"2015-01-14T06:53:27Z","updated_at":"2015-02-17T16:38:08Z","pushed_at":"2015-02-18T03:13:52Z","git_url":"git://github.com/hdavidzhu/olinjs.git","ssh_url":"git@github.com:hdavidzhu/olinjs.git","clone_url":"https://github.com/hdavidzhu/olinjs.git","svn_url":"https://github.com/hdavidzhu/olinjs","homepage":null,"size":3927,"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":4,"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3"},"html":{"href":"https://github.com/hdavidzhu/olinjs/pull/3"},"issue":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/issues/3"},"comments":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/hdavidzhu/olinjs/statuses/4c4d37d2f6f41ee7878f1c21e73c9226542242d3"}}}}