From 965781ee03e2299aab7c06459bb12c29fb07fe45 Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 14 Jun 2016 14:45:12 -0700 Subject: [PATCH 01/46] pseudo code of routes --- routes/routes.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 routes/routes.js diff --git a/routes/routes.js b/routes/routes.js new file mode 100644 index 000000000..b10e33d3c --- /dev/null +++ b/routes/routes.js @@ -0,0 +1,23 @@ +// Needed API endpoints w/HTTP verbs +// +// GET (/customers) +// +// GET (/customers/sort/name?n=10&p=2) +// name (n) +// registered_at (r) +// postal_code (p) +// GET (/customers/:id/current) +// GET (/customers/:id/history) +// +// GET (/movies) +// GET (/movies/sort/release-date?n=5&p=1) +// title +// release_date +// GET (/movies/:title/current) +// GET (/movies/:title/history/sort/name) +// +// GET (/rentals/:title) +// GET (/rentals/:title/customers) +// UPDATE (/rentals/:id/:title/check-out) +// UPDATE (/rentals/:id/:title/return) +// GET (/rentals/overdue) From c854c70417f70fae61d08fb066f4d82263aab4e8 Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 14 Jun 2016 15:08:38 -0700 Subject: [PATCH 02/46] zomg it works displaying --- app.js | 2 ++ routes/{routes.js => zomg.js} | 11 +++++++++++ 2 files changed, 13 insertions(+) rename routes/{routes.js => zomg.js} (71%) diff --git a/app.js b/app.js index f0579b1dc..8c8011d2c 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,7 @@ var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var routes = require('./routes/index'); +var zomgRoutes = require('./routes/zomg') var app = express(); @@ -22,6 +23,7 @@ app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); +app.use('/zomg', zomgRoutes) // catch 404 and forward to error handler app.use(function(req, res, next) { diff --git a/routes/routes.js b/routes/zomg.js similarity index 71% rename from routes/routes.js rename to routes/zomg.js index b10e33d3c..98992695d 100644 --- a/routes/routes.js +++ b/routes/zomg.js @@ -21,3 +21,14 @@ // UPDATE (/rentals/:id/:title/check-out) // UPDATE (/rentals/:id/:title/return) // GET (/rentals/overdue) + +var express = require('express'); +var router = express.Router(); +var locals = {} + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.status(200).json({whatevs: 'zomg!!!'}) +}); + +module.exports = router; From 9b092da79a07d6549538c56151451aaed5014b1c Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 14 Jun 2016 15:57:43 -0700 Subject: [PATCH 03/46] working on scripts --- package.json | 8 +++++++- tasks/db_create.js | 14 ++++++++++++++ tasks/db_drop.js | 10 ++++++++++ tasks/load_schema.js | 10 ++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tasks/db_create.js create mode 100644 tasks/db_drop.js create mode 100644 tasks/load_schema.js diff --git a/package.json b/package.json index d39b26403..4f12622b9 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,13 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/" + "test": "clear; jasmine-node --verbose spec/", + "db:drop": "dropdb scrabble_express", + "db:create": "createdb scrabble_express", + "db:schema": "node tasks/load_schema.js", + "db:seed": "", + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" + }, "dependencies": { "body-parser": "~1.13.2", diff --git a/tasks/db_create.js b/tasks/db_create.js new file mode 100644 index 000000000..216708233 --- /dev/null +++ b/tasks/db_create.js @@ -0,0 +1,14 @@ +var massive = require('massive') +var connectionString = "postgres://localhost/videostoreapi" + +var db = massive.connectSync({connectionString : connectionString}) + +db.run(“CREATE DATABASE "videostoreapi";”, function(err, res){ +}if (err){ throw(newError(err.message))} +console.log(res) +process.exit() +}) + + console.log("yay new DATABASE") + process.exit() +}) diff --git a/tasks/db_drop.js b/tasks/db_drop.js new file mode 100644 index 000000000..766ce1de9 --- /dev/null +++ b/tasks/db_drop.js @@ -0,0 +1,10 @@ +var massive = require(‘massive’) + var connectionString = "postgres://localhost/videostoreapi" + var db = massive.connectSync({connectionString : connectionString}) + db.setup.schema([],function(err,res)){ + if(err){ + } throw(new Error(err.message)) + } + console.log(“yay schema!”) + process.exit() + }) diff --git a/tasks/load_schema.js b/tasks/load_schema.js new file mode 100644 index 000000000..d6a0dc26a --- /dev/null +++ b/tasks/load_schema.js @@ -0,0 +1,10 @@ +var massive = require(‘massive’) + var connectionString = "postgres://localhost/videostoreapi" + var db = massive.connectSync({connectionString : connectionString}) + db.setup.schema([],function(err,res)){ + if(err){ + } throw(new Error(err.message)) + } + console.log(“yay schema!”) + process.exit() + }) From 6b17799e3e8870fe0a85fd3093f2ea09426ee96f Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 14 Jun 2016 16:30:27 -0700 Subject: [PATCH 04/46] trying to get scripts for schema working --- db/setup/schema.sql | 10 +++++++++ db/setup/seed.sql | 0 npm-debug.log | 48 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 6 +++--- tasks/db_create.js | 4 ++-- tasks/db_drop.js | 2 +- tasks/load_schema.js | 19 ++++++++++-------- 7 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 db/setup/schema.sql create mode 100644 db/setup/seed.sql create mode 100644 npm-debug.log diff --git a/db/setup/schema.sql b/db/setup/schema.sql new file mode 100644 index 000000000..fbc164ce7 --- /dev/null +++ b/db/setup/schema.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS movies; +CREATE TABLE movies( + id serial PRIMARY KEY, + title text, + overview text, + release_date text, + inventory_total text, +); + +CREATE INDEX movies_movie ON movies (movie); diff --git a/db/setup/seed.sql b/db/setup/seed.sql new file mode 100644 index 000000000..e69de29bb diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 000000000..4eec514aa --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,48 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/Cellar/node/6.2.1/bin/node', +1 verbose cli '/usr/local/bin/npm', +1 verbose cli 'run', +1 verbose cli 'db:schema' ] +2 info using npm@3.9.3 +3 info using node@v6.2.1 +4 verbose run-script [ 'predb:schema', 'db:schema', 'postdb:schema' ] +5 info lifecycle video-store-api@0.0.0~predb:schema: video-store-api@0.0.0 +6 silly lifecycle video-store-api@0.0.0~predb:schema: no script for predb:schema, continuing +7 info lifecycle video-store-api@0.0.0~db:schema: video-store-api@0.0.0 +8 verbose lifecycle video-store-api@0.0.0~db:schema: unsafe-perm in lifecycle true +9 verbose lifecycle video-store-api@0.0.0~db:schema: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/justinewinnie/Desktop/c5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/justinewinnie/.rvm/gems/ruby-2.3.0/bin:/Users/justinewinnie/.rvm/gems/ruby-2.3.0@global/bin:/Users/justinewinnie/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/justinewinnie/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~db:schema: CWD: /Users/justinewinnie/Desktop/c5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~db:schema: Args: [ '-c', 'node tasks/load_schema.js' ] +12 silly lifecycle video-store-api@0.0.0~db:schema: Returned: code: 1 signal: null +13 info lifecycle video-store-api@0.0.0~db:schema: Failed to exec db:schema script +14 verbose stack Error: video-store-api@0.0.0 db:schema: `node tasks/load_schema.js` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:245:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:852:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) +15 verbose pkgid video-store-api@0.0.0 +16 verbose cwd /Users/justinewinnie/Desktop/c5/projects/VideoStoreAPI +17 error Darwin 15.5.0 +18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "db:schema" +19 error node v6.2.1 +20 error npm v3.9.3 +21 error code ELIFECYCLE +22 error video-store-api@0.0.0 db:schema: `node tasks/load_schema.js` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 db:schema script 'node tasks/load_schema.js'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the video-store-api package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error node tasks/load_schema.js +23 error You can get information on how to open an issue for this project with: +23 error npm bugs video-store-api +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls video-store-api +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 4f12622b9..18b7e4c4d 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,11 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:drop": "dropdb scrabble_express", - "db:create": "createdb scrabble_express", + "db:drop": "dropdb video-store-api", + "db:create": "createdb video-store-api", "db:schema": "node tasks/load_schema.js", "db:seed": "", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" - }, "dependencies": { "body-parser": "~1.13.2", @@ -18,6 +17,7 @@ "debug": "~2.2.0", "express": "~4.13.1", "jade": "~1.11.0", + "massive": "^2.3.0", "morgan": "~1.6.1", "sequelize": "^3.23.3", "serve-favicon": "~2.3.0" diff --git a/tasks/db_create.js b/tasks/db_create.js index 216708233..3e0d40466 100644 --- a/tasks/db_create.js +++ b/tasks/db_create.js @@ -1,9 +1,9 @@ var massive = require('massive') -var connectionString = "postgres://localhost/videostoreapi" +var connectionString = "postgres://localhost/video-store-api" var db = massive.connectSync({connectionString : connectionString}) -db.run(“CREATE DATABASE "videostoreapi";”, function(err, res){ +db.run(“CREATE DATABASE "video-store-api";”, function(err, res){ }if (err){ throw(newError(err.message))} console.log(res) process.exit() diff --git a/tasks/db_drop.js b/tasks/db_drop.js index 766ce1de9..96942f110 100644 --- a/tasks/db_drop.js +++ b/tasks/db_drop.js @@ -1,5 +1,5 @@ var massive = require(‘massive’) - var connectionString = "postgres://localhost/videostoreapi" + var connectionString = "postgres://localhost/video-store-api" var db = massive.connectSync({connectionString : connectionString}) db.setup.schema([],function(err,res)){ if(err){ diff --git a/tasks/load_schema.js b/tasks/load_schema.js index d6a0dc26a..e2957024a 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,10 +1,13 @@ -var massive = require(‘massive’) - var connectionString = "postgres://localhost/videostoreapi" - var db = massive.connectSync({connectionString : connectionString}) - db.setup.schema([],function(err,res)){ - if(err){ - } throw(new Error(err.message)) +var massive = require("massive") +var connectionString = "postgres://localhost/video-store-api" + +var db = massive.connectSync({connectionString : connectionString}) + +db.setup.schema([], function(err, res) { + if (err) { + throw new Error(err.message) } - console.log(“yay schema!”) + + console.log("yay schema!") process.exit() - }) +}) From 51364caf9772f88b8c8a0c33ceb503d478fd44e3 Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 15 Jun 2016 15:09:24 -0700 Subject: [PATCH 05/46] finally found load_schema typo, started adding seed script --- db/setup/schema.sql | 4 ++-- npm-debug.log | 48 --------------------------------------------- package.json | 3 +-- tasks/seed.js | 0 4 files changed, 3 insertions(+), 52 deletions(-) delete mode 100644 npm-debug.log create mode 100644 tasks/seed.js diff --git a/db/setup/schema.sql b/db/setup/schema.sql index fbc164ce7..8ecc070f1 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -4,7 +4,7 @@ CREATE TABLE movies( title text, overview text, release_date text, - inventory_total text, + inventory_total text ); -CREATE INDEX movies_movie ON movies (movie); +CREATE INDEX movies_movie ON movies (title); diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 4eec514aa..000000000 --- a/npm-debug.log +++ /dev/null @@ -1,48 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/local/Cellar/node/6.2.1/bin/node', -1 verbose cli '/usr/local/bin/npm', -1 verbose cli 'run', -1 verbose cli 'db:schema' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'predb:schema', 'db:schema', 'postdb:schema' ] -5 info lifecycle video-store-api@0.0.0~predb:schema: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~predb:schema: no script for predb:schema, continuing -7 info lifecycle video-store-api@0.0.0~db:schema: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~db:schema: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~db:schema: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/justinewinnie/Desktop/c5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/justinewinnie/.rvm/gems/ruby-2.3.0/bin:/Users/justinewinnie/.rvm/gems/ruby-2.3.0@global/bin:/Users/justinewinnie/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/justinewinnie/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~db:schema: CWD: /Users/justinewinnie/Desktop/c5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~db:schema: Args: [ '-c', 'node tasks/load_schema.js' ] -12 silly lifecycle video-store-api@0.0.0~db:schema: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~db:schema: Failed to exec db:schema script -14 verbose stack Error: video-store-api@0.0.0 db:schema: `node tasks/load_schema.js` -14 verbose stack Exit status 1 -14 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:245:16) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at EventEmitter.emit (events.js:191:7) -14 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:24:14) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at ChildProcess.emit (events.js:191:7) -14 verbose stack at maybeClose (internal/child_process.js:852:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) -15 verbose pkgid video-store-api@0.0.0 -16 verbose cwd /Users/justinewinnie/Desktop/c5/projects/VideoStoreAPI -17 error Darwin 15.5.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "db:schema" -19 error node v6.2.1 -20 error npm v3.9.3 -21 error code ELIFECYCLE -22 error video-store-api@0.0.0 db:schema: `node tasks/load_schema.js` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 db:schema script 'node tasks/load_schema.js'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the video-store-api package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error node tasks/load_schema.js -23 error You can get information on how to open an issue for this project with: -23 error npm bugs video-store-api -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls video-store-api -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index 18b7e4c4d..544d05ced 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "db:drop": "dropdb video-store-api", "db:create": "createdb video-store-api", "db:schema": "node tasks/load_schema.js", - "db:seed": "", + "db:seed": "node tasks/seed.js", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" }, "dependencies": { @@ -19,7 +19,6 @@ "jade": "~1.11.0", "massive": "^2.3.0", "morgan": "~1.6.1", - "sequelize": "^3.23.3", "serve-favicon": "~2.3.0" }, "devDependencies": { diff --git a/tasks/seed.js b/tasks/seed.js new file mode 100644 index 000000000..e69de29bb From 16a652d52eff463289c7e0d549d27fb8b899652f Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 15 Jun 2016 15:44:33 -0700 Subject: [PATCH 06/46] added schema working on seeding data --- tasks/seed.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tasks/seed.js b/tasks/seed.js index e69de29bb..b8a3ea3aa 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -0,0 +1,18 @@ +var massive = require('massive'); + var connectionString = 'postgres://localhost/video-store-api'; + var db = massive.connectSync({connectionString : connectionString}); + var data = require('../db/seeds/movies.json'); + //var data = require('../db/seeds/customers.json'); + + for (var record of data) { + db.movies.save(record, function(err, res) { + console.log('saved: ', JSON.stringify(res)) + }) +} + // for (var record of data){ console.log,record.rental_id, record.name, record.reg_date, record.address, + // record.city,record.state,record.postal_code,record.phone,record.acct_credit + // db.customers.saveSync({record}) + //} + + +process.exit() From dcc01d6f5efc94beef2aec6692e403c2043a3451 Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 15 Jun 2016 15:53:13 -0700 Subject: [PATCH 07/46] got movies to seed! --- db/setup/schema.sql | 2 +- tasks/seed.js | 31 ++++++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 8ecc070f1..a88c58434 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -4,7 +4,7 @@ CREATE TABLE movies( title text, overview text, release_date text, - inventory_total text + inventory text ); CREATE INDEX movies_movie ON movies (title); diff --git a/tasks/seed.js b/tasks/seed.js index b8a3ea3aa..9c726f268 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -1,18 +1,23 @@ var massive = require('massive'); - var connectionString = 'postgres://localhost/video-store-api'; - var db = massive.connectSync({connectionString : connectionString}); - var data = require('../db/seeds/movies.json'); - //var data = require('../db/seeds/customers.json'); +var connectionString = 'postgres://localhost/video-store-api'; +var db = massive.connectSync({connectionString : connectionString}); +var data = require('../db/seeds/movies.json'); +//var data = require('../db/seeds/customers.json'); - for (var record of data) { - db.movies.save(record, function(err, res) { - console.log('saved: ', JSON.stringify(res)) - }) -} - // for (var record of data){ console.log,record.rental_id, record.name, record.reg_date, record.address, - // record.city,record.state,record.postal_code,record.phone,record.acct_credit - // db.customers.saveSync({record}) - //} +// for (var record of data) { +// db.movies.save(record, function(err, res) { +// console.log('saved: ', JSON.stringify(res)) +// }) +// } +for (var record of data) { + console.log(record.id, record.title, record.overview, record.release_date, record.inventory_total) + // { word: "elephant", score: 63 } + db.movies.saveSync(record) +} +// for (var record of data){ console.log,record.rental_id, record.name, record.reg_date, record.address, +// record.city,record.state,record.postal_code,record.phone,record.acct_credit +// db.customers.saveSync({record}) +// } process.exit() From 6f4af582024c39122d32afd9bfb0a59ac5a4b935 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 16 Jun 2016 14:04:51 -0700 Subject: [PATCH 08/46] renamed data vars in seed.js to differentiate between tables. seeding successfully. --- db/setup/schema.sql | 18 +++++++++++++++++- tasks/seed.js | 24 ++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index a88c58434..e04b368da 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -7,4 +7,20 @@ CREATE TABLE movies( inventory text ); -CREATE INDEX movies_movie ON movies (title); +-- CREATE INDEX movies_movie ON movies (title); + + +DROP TABLE IF EXISTS customers; +CREATE TABLE customers( + id serial PRIMARY KEY, + name text, + registered_at text, + address text, + city text, + state text, + postal_code text, + phone text, + account_credit float +); + +-- CREATE INDEX customers_customer ON customers (name); diff --git a/tasks/seed.js b/tasks/seed.js index 9c726f268..97d68bd10 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -1,23 +1,19 @@ var massive = require('massive'); var connectionString = 'postgres://localhost/video-store-api'; var db = massive.connectSync({connectionString : connectionString}); -var data = require('../db/seeds/movies.json'); -//var data = require('../db/seeds/customers.json'); +var movies = require('../db/seeds/movies.json'); +var customers = require('../db/seeds/customers.json'); -// for (var record of data) { -// db.movies.save(record, function(err, res) { -// console.log('saved: ', JSON.stringify(res)) -// }) -// } +for (var movie of movies) { + console.log(movie) + // { word: "elephant", score: 63 } + db.movies.saveSync(movie) +} -for (var record of data) { - console.log(record.id, record.title, record.overview, record.release_date, record.inventory_total) +for (var customer of customers) { + console.log(customer) // { word: "elephant", score: 63 } - db.movies.saveSync(record) + db.customers.saveSync(customer) } -// for (var record of data){ console.log,record.rental_id, record.name, record.reg_date, record.address, -// record.city,record.state,record.postal_code,record.phone,record.acct_credit -// db.customers.saveSync({record}) -// } process.exit() From 62634c95b765a2495837e73da3ea1b42b5b58f4b Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 16 Jun 2016 14:23:08 -0700 Subject: [PATCH 09/46] created schema for empty rentals table, cleaned up some comments --- controllers/customers_controller.js | 0 controllers/movies_controller.js | 0 controllers/rentals_controller.js | 0 db/setup/schema.sql | 16 ++++++++++++---- tasks/db_drop.js | 19 ++++++++++--------- tasks/seed.js | 12 +++++------- 6 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 controllers/customers_controller.js create mode 100644 controllers/movies_controller.js create mode 100644 controllers/rentals_controller.js diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js new file mode 100644 index 000000000..e69de29bb diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js new file mode 100644 index 000000000..e69de29bb diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js new file mode 100644 index 000000000..e69de29bb diff --git a/db/setup/schema.sql b/db/setup/schema.sql index e04b368da..c757a82ef 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -7,9 +7,6 @@ CREATE TABLE movies( inventory text ); --- CREATE INDEX movies_movie ON movies (title); - - DROP TABLE IF EXISTS customers; CREATE TABLE customers( id serial PRIMARY KEY, @@ -23,4 +20,15 @@ CREATE TABLE customers( account_credit float ); --- CREATE INDEX customers_customer ON customers (name); +DROP TABLE IF EXISTS rentals; +CREATE TABLE rentals( + id serial PRIMARY KEY, + movie_id text, + title text, + overview text, + release_date text, + inventory_available text, + inventory text, + checkout_date text, + due_date text +); diff --git a/tasks/db_drop.js b/tasks/db_drop.js index 96942f110..5ca18b05b 100644 --- a/tasks/db_drop.js +++ b/tasks/db_drop.js @@ -1,10 +1,11 @@ var massive = require(‘massive’) - var connectionString = "postgres://localhost/video-store-api" - var db = massive.connectSync({connectionString : connectionString}) - db.setup.schema([],function(err,res)){ - if(err){ - } throw(new Error(err.message)) - } - console.log(“yay schema!”) - process.exit() - }) +var connectionString = "postgres://localhost/video-store-api" +var db = massive.connectSync({connectionString : connectionString}) + +db.setup.schema([],function(err,res)){ + if(err){ + } throw(new Error(err.message)) +} +console.log(“yay schema!”) +process.exit() +}) diff --git a/tasks/seed.js b/tasks/seed.js index 97d68bd10..1a9ca57d2 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -1,18 +1,16 @@ -var massive = require('massive'); -var connectionString = 'postgres://localhost/video-store-api'; -var db = massive.connectSync({connectionString : connectionString}); -var movies = require('../db/seeds/movies.json'); -var customers = require('../db/seeds/customers.json'); +var massive = require('massive') +var connectionString = 'postgres://localhost/video-store-api' +var db = massive.connectSync({connectionString : connectionString}) +var movies = require('../db/seeds/movies.json') +var customers = require('../db/seeds/customers.json') for (var movie of movies) { console.log(movie) - // { word: "elephant", score: 63 } db.movies.saveSync(movie) } for (var customer of customers) { console.log(customer) - // { word: "elephant", score: 63 } db.customers.saveSync(customer) } From 194fc04ec6ce28b39a562b23039a63739c1225e6 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 16 Jun 2016 14:26:05 -0700 Subject: [PATCH 10/46] starting to work on models/wrappers --- controllers/movies_controller.js | 39 ++++++++++++++++++++++++++++++++ models/customers.js | 0 models/movies.js | 0 models/rentals.js | 0 4 files changed, 39 insertions(+) create mode 100644 models/customers.js create mode 100644 models/movies.js create mode 100644 models/rentals.js diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index e69de29bb..ebfa9c977 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -0,0 +1,39 @@ +// var Movie = require("../models/account"); +// +// var AccountsController = { +// index: function(req, res, next) { +// Account.all(function(error, accounts) { +// if(error) { +// var err = new Error("Error retrieving account list:\n" + error.message); +// err.status = 500; +// next(err); +// } else { +// res.json(accounts) +// // res.render("accounts/index", { +// // accounts: accounts +// // }); +// } +// }); +// }, +// +// show: function(req, res, next) { +// Account.find(req.params.id, function(error, account) { +// if(error) { +// var err = new Error("No such account"); +// err.status = 404; +// next(err); +// } else { +// account.getBalance(function(error, balance) { +// res.render("accounts/show", { +// account: { +// id: account.id, +// balance: balance +// } +// }); +// }); +// } +// }); +// } +// }; +// +// module.exports = AccountsController; diff --git a/models/customers.js b/models/customers.js new file mode 100644 index 000000000..e69de29bb diff --git a/models/movies.js b/models/movies.js new file mode 100644 index 000000000..e69de29bb diff --git a/models/rentals.js b/models/rentals.js new file mode 100644 index 000000000..e69de29bb From c5aac1704f57044424d62941422dfe5c87c3454e Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 16 Jun 2016 15:55:43 -0700 Subject: [PATCH 11/46] fixed requires and db issues --- app.js | 70 ++++++++------- controllers/movies_controller.js | 78 ++++++++-------- models/{customers.js => customer.js} | 0 models/movie.js | 129 +++++++++++++++++++++++++++ models/{movies.js => rental.js} | 0 models/rentals.js | 0 routes/index.js | 13 ++- 7 files changed, 214 insertions(+), 76 deletions(-) rename models/{customers.js => customer.js} (100%) create mode 100644 models/movie.js rename models/{movies.js => rental.js} (100%) delete mode 100644 models/rentals.js diff --git a/app.js b/app.js index 8c8011d2c..82374468a 100644 --- a/app.js +++ b/app.js @@ -1,36 +1,43 @@ -var express = require('express'); -var path = require('path'); -var favicon = require('serve-favicon'); -var logger = require('morgan'); -var cookieParser = require('cookie-parser'); -var bodyParser = require('body-parser'); - -var routes = require('./routes/index'); -var zomgRoutes = require('./routes/zomg') +var express = require('express') +var path = require('path') +var favicon = require('serve-favicon') +var logger = require('morgan') +var cookieParser = require('cookie-parser') +var bodyParser = require('body-parser') + +var massive = require('massive') +var connectionString = "postgres://localhost/video-store-api" + -var app = express(); +var app = module.exports = express() + +var db = massive.connectSync({connectionString : connectionString}) +app.set('db', db) // view engine setup -app.set('views', path.join(__dirname, 'views')); -app.set('view engine', 'jade'); +app.set('views', path.join(__dirname, 'views')) +app.set('view engine', 'jade') + +var routes = require('./routes/index') +var zomgRoutes = require('./routes/zomg') // uncomment after placing your favicon in /public -//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); -app.use(logger('dev')); -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: false })); -app.use(cookieParser()); -app.use(express.static(path.join(__dirname, 'public'))); - -app.use('/', routes); +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))) +app.use(logger('dev')) +app.use(bodyParser.json()) +app.use(bodyParser.urlencoded({ extended: false })) +app.use(cookieParser()) +app.use(express.static(path.join(__dirname, 'public'))) + +app.use('/', routes) app.use('/zomg', zomgRoutes) // catch 404 and forward to error handler app.use(function(req, res, next) { - var err = new Error('Not Found'); - err.status = 404; - next(err); -}); + var err = new Error('Not Found') + err.status = 404 + next(err) +}) // error handlers @@ -38,23 +45,20 @@ app.use(function(req, res, next) { // will print stacktrace if (app.get('env') === 'development') { app.use(function(err, req, res, next) { - res.status(err.status || 500); + res.status(err.status || 500) res.render('error', { message: err.message, error: err - }); - }); + }) + }) } // production error handler // no stacktraces leaked to user app.use(function(err, req, res, next) { - res.status(err.status || 500); + res.status(err.status || 500) res.render('error', { message: err.message, error: {} - }); -}); - - -module.exports = app; + }) +}) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index ebfa9c977..66c099a0c 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -1,39 +1,39 @@ -// var Movie = require("../models/account"); -// -// var AccountsController = { -// index: function(req, res, next) { -// Account.all(function(error, accounts) { -// if(error) { -// var err = new Error("Error retrieving account list:\n" + error.message); -// err.status = 500; -// next(err); -// } else { -// res.json(accounts) -// // res.render("accounts/index", { -// // accounts: accounts -// // }); -// } -// }); -// }, -// -// show: function(req, res, next) { -// Account.find(req.params.id, function(error, account) { -// if(error) { -// var err = new Error("No such account"); -// err.status = 404; -// next(err); -// } else { -// account.getBalance(function(error, balance) { -// res.render("accounts/show", { -// account: { -// id: account.id, -// balance: balance -// } -// }); -// }); -// } -// }); -// } -// }; -// -// module.exports = AccountsController; +var Movie = require("../models/movie") + +var MoviesController = { + index: function(req, res, next) { + Movie.getAll(function(error, movies) { + if(error) { + var err = new Error("Error retrieving movies:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(movies) + // res.render("accounts/index", { + // accounts: accounts + // }) + } + }) + }, + + // show: function(req, res, next) { + // Account.find(req.params.id, function(error, account) { + // if(error) { + // var err = new Error("No such account") + // err.status = 404 + // next(err) + // } else { + // account.getBalance(function(error, balance) { + // res.render("accounts/show", { + // account: { + // id: account.id, + // balance: balance + // } + // }) + // }) + // } + // }) + // } +} + +module.exports = MoviesController diff --git a/models/customers.js b/models/customer.js similarity index 100% rename from models/customers.js rename to models/customer.js diff --git a/models/movie.js b/models/movie.js new file mode 100644 index 000000000..3556bb2cd --- /dev/null +++ b/models/movie.js @@ -0,0 +1,129 @@ +var app = require("../app") + + + + +var db = app.get('db') +console.log(db) + +// Constructor function +var Movie = function(id) { + this.id = id +} + +// Instance functions +// get a list of all movies /movies +// get a subset of movies - sort by release date or by title +// return n movie records, with p (per page) +// given a title, get list of customers who are CURRENTLY renting the title +// include cust name, phone no, and acct_credit +// get list of customers who have rented title in the past - sort by cust name or checkout_date +// include cust name, phone no, and acct_credit + +Movie.getAll = function(callback) { + db.movies.find(function(error, movies) { + if(error) { + callback(error || new Error("Could not retrieve movies"), undefined) + } else if(!movies) { + callback(error || new Error("No movies found"), undefined) + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie.id) + })) + } + }) + +// sort by release date or by title +} + +Movie.prototype.getSubset = function(number, pages, callback) { +// return n movie records, with p (per page) +// sort by release date or by title + +} + +Movie.prototype.getByTitle = function(title, callback) { +// get list of customers who are CURRENTLY renting the title +// include cust name, phone no, and acct_credit + +// get list of customers who have PAST rented the title +} + +var balanceResultCallback = function(movie, callback) { + return function(error, result) { + if(error) { + callback(error, undefined) + } else { + account.getBalance(function(error, balance) { + callback(error, balance) + }) + } + } +} + +// Movie.prototype.deposit = function(amount, callback) { +// db.accounts_deposit(this.id, amount, balanceResultCallback(this, callback)) +// return this +// } +// +// Movie.prototype.withdraw = function(amount, callback) { +// db.accounts_withdraw(this.id, amount, balanceResultCallback(this, callback)) +// return this +// } +// +// Movie.prototype.transfer = function(to, amount, callback) { +// db.accounts_transfer(this.id, to.id, amount, balanceResultCallback(this, callback)) +// return this +// } +// +// // Class Functions +// Movie.create = function(initialBalance, callback) { +// db.accounts.save({ +// balance: initialBalance +// }, function(error, account) { +// if(error || !account) { +// callback(error || new Error("Could not create account"), undefined) +// } else { +// callback(null, new Movie(account.id)) +// } +// }) +// } +// +// Movie.createSync = function(initialBalance) { +// var account = db.accounts.saveSync({ +// balance: initialBalance +// }) +// +// return new Movie(account.id) +// } +// +// Movie.all = function(callback) { +// db.accounts.find(function(error, accounts) { +// if(error || !accounts) { +// callback(error || new Error("Could not retrieve accounts"), undefined) +// } else { +// callback(null, accounts.map(function(account) { +// return new Movie(account.id) +// })) +// } +// }) +// } +// +// Movie.find = function(id, callback) { +// db.accounts.findOne({id: id}, function(error, account) { +// if(error || !account) { +// callback(error || new Error("Movie not found"), undefined) +// } else { +// callback(null, new Movie(account.id)) +// } +// }) +// } +// +// // only attach this function if we're in test mode +// if (app.get('env') === 'test') { +// Movie.close_connection = function() { +// console.log("closing connection") +// db.end() +// } +// } +module.exports = Movie diff --git a/models/movies.js b/models/rental.js similarity index 100% rename from models/movies.js rename to models/rental.js diff --git a/models/rentals.js b/models/rentals.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/routes/index.js b/routes/index.js index 06cfc1137..83cef1fa4 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,9 +1,14 @@ -var express = require('express'); -var router = express.Router(); +var express = require('express') +var router = express.Router() +var controller = require('../controllers/movies_controller') /* GET home page. */ router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) -}); +}) -module.exports = router; +router.get('/movies', function(req, res, next) { + controller.index(req, res, next) +}) + +module.exports = router From c8fab73cb70df79be6f7ddb3c5d48af0fe38e213 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 16 Jun 2016 16:31:27 -0700 Subject: [PATCH 12/46] all movie data displaying --- controllers/movies_controller.js | 4 +++- models/movie.js | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index 66c099a0c..b282abe81 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -2,13 +2,15 @@ var Movie = require("../models/movie") var MoviesController = { index: function(req, res, next) { - Movie.getAll(function(error, movies) { + Movie.all(function(error, movies) { if(error) { var err = new Error("Error retrieving movies:\n" + error.message) err.status = 500 next(err) } else { res.json(movies) + console.log(res) + // res.render("accounts/index", { // accounts: accounts // }) diff --git a/models/movie.js b/models/movie.js index 3556bb2cd..f12c60efd 100644 --- a/models/movie.js +++ b/models/movie.js @@ -1,10 +1,5 @@ var app = require("../app") - - - - var db = app.get('db') -console.log(db) // Constructor function var Movie = function(id) { @@ -20,7 +15,7 @@ var Movie = function(id) { // get list of customers who have rented title in the past - sort by cust name or checkout_date // include cust name, phone no, and acct_credit -Movie.getAll = function(callback) { +Movie.all = function(callback) { db.movies.find(function(error, movies) { if(error) { callback(error || new Error("Could not retrieve movies"), undefined) @@ -28,7 +23,7 @@ Movie.getAll = function(callback) { callback(error || new Error("No movies found"), undefined) } else { callback(null, movies.map(function(movie) { - return new Movie(movie.id) + return new Movie(movie) })) } }) @@ -36,6 +31,8 @@ Movie.getAll = function(callback) { // sort by release date or by title } + + Movie.prototype.getSubset = function(number, pages, callback) { // return n movie records, with p (per page) // sort by release date or by title From eadc37856cf6be07adeee7330b029d8b7739d1dd Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 17 Jun 2016 11:02:47 -0700 Subject: [PATCH 13/46] working on bug in controller --- controllers/movies_controller.js | 55 +++++++++++++++++++++++++++++--- models/movie.js | 41 ++++++++++++++++++++++++ routes/index.js | 6 ++++ 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index b282abe81..1e8305be3 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -1,6 +1,7 @@ var Movie = require("../models/movie") var MoviesController = { + index: function(req, res, next) { Movie.all(function(error, movies) { if(error) { @@ -14,9 +15,56 @@ var MoviesController = { // res.render("accounts/index", { // accounts: accounts // }) + } + + + + getSubset: function(req, res, next){ + Movie.all(function(error, movies) { + if(error) { + var err = new Error("Error retrieving movies:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(movies) + console.log(res) + + } }) - }, + } +} + + +module.exports = MoviesController + + + + +// res.render("accounts/index", { +// accounts: accounts +// }) + + +// getSubset: function(req, res, next) { +// Movie.all(function(error, movies) { +// if(error) { +// var err = new Error("Error retrieving movies:\n" + error.message) +// err.status = 500 +// next(err) +// } else { +// res.json(movies) +// console.log(res) +// +// // res.render("accounts/index", { +// // accounts: accounts +// // }) +// } +// } +// }) + + + // show: function(req, res, next) { // Account.find(req.params.id, function(error, account) { @@ -35,7 +83,4 @@ var MoviesController = { // }) // } // }) - // } -} - -module.exports = MoviesController + // diff --git a/models/movie.js b/models/movie.js index f12c60efd..cdb6126a0 100644 --- a/models/movie.js +++ b/models/movie.js @@ -34,6 +34,47 @@ Movie.all = function(callback) { Movie.prototype.getSubset = function(number, pages, callback) { + var options_release_date = { + number : number, + order : release_date, + offset : pages + } + + db.movies.find({}, options_release_date, function(err, movies){ + if(error) { + callback(error || new Error("Could not retrieve movies"), undefined) + } else if(!movies) { + callback(error || new Error("No movies found"), undefined) + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie) + })) + } + + }) + + var options_title = { + number : number, + order : title, + offset : pages + } + + db.movies.find({}, options_title, function(err, movies){ + if(error) { + callback(error || new Error("Could not retrieve movies"), undefined) + } else if(!movies) { + callback(error || new Error("No movies found"), undefined) + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie) + })) + } + + }) + + + + // return n movie records, with p (per page) // sort by release date or by title diff --git a/routes/index.js b/routes/index.js index 83cef1fa4..e0b481f25 100644 --- a/routes/index.js +++ b/routes/index.js @@ -10,5 +10,11 @@ router.get('/', function(req, res, next) { router.get('/movies', function(req, res, next) { controller.index(req, res, next) }) +//n = number of resultes +//p = page number + +router.get('/movies/sort/title?n=:number&p=:pages', function(req, res, next){ +controller.subset(req, res, next) +}) module.exports = router From 6c6c2e69acb12327babb59d58792ad8ac23c79ee Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 17 Jun 2016 11:17:48 -0700 Subject: [PATCH 14/46] fixed rude braces. --- controllers/movies_controller.js | 15 ++++----------- models/movie.js | 9 +++------ routes/index.js | 4 ++-- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index 1e8305be3..a8b854dfb 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -11,15 +11,11 @@ var MoviesController = { } else { res.json(movies) console.log(res) + } + }) + }, - // res.render("accounts/index", { - // accounts: accounts - // }) - } - - - - getSubset: function(req, res, next){ + getSubset: function(req, res, next) { Movie.all(function(error, movies) { if(error) { var err = new Error("Error retrieving movies:\n" + error.message) @@ -28,14 +24,11 @@ var MoviesController = { } else { res.json(movies) console.log(res) - - } }) } } - module.exports = MoviesController diff --git a/models/movie.js b/models/movie.js index cdb6126a0..e2dad31a0 100644 --- a/models/movie.js +++ b/models/movie.js @@ -27,8 +27,6 @@ Movie.all = function(callback) { })) } }) - -// sort by release date or by title } @@ -40,7 +38,7 @@ Movie.prototype.getSubset = function(number, pages, callback) { offset : pages } - db.movies.find({}, options_release_date, function(err, movies){ + db.movies.find({}, options_release_date, function(err, movies) { if(error) { callback(error || new Error("Could not retrieve movies"), undefined) } else if(!movies) { @@ -59,7 +57,7 @@ Movie.prototype.getSubset = function(number, pages, callback) { offset : pages } - db.movies.find({}, options_title, function(err, movies){ + db.movies.find({}, options_title, function(err, movies) { if(error) { callback(error || new Error("Could not retrieve movies"), undefined) } else if(!movies) { @@ -69,8 +67,8 @@ Movie.prototype.getSubset = function(number, pages, callback) { return new Movie(movie) })) } - }) +} @@ -78,7 +76,6 @@ Movie.prototype.getSubset = function(number, pages, callback) { // return n movie records, with p (per page) // sort by release date or by title -} Movie.prototype.getByTitle = function(title, callback) { // get list of customers who are CURRENTLY renting the title diff --git a/routes/index.js b/routes/index.js index e0b481f25..b6f759a69 100644 --- a/routes/index.js +++ b/routes/index.js @@ -13,8 +13,8 @@ router.get('/movies', function(req, res, next) { //n = number of resultes //p = page number -router.get('/movies/sort/title?n=:number&p=:pages', function(req, res, next){ -controller.subset(req, res, next) +router.get('/movies/sort/title?n=:number&p=:pages', function(req, res, next) { + controller.subset(req, res, next) }) module.exports = router From 704d04c916dc3fe3e8b3cf25cc9858cf153b4e96 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 17 Jun 2016 11:18:38 -0700 Subject: [PATCH 15/46] bug fixed --- controllers/movies_controller.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index 1e8305be3..a8b854dfb 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -11,15 +11,11 @@ var MoviesController = { } else { res.json(movies) console.log(res) + } + }) + }, - // res.render("accounts/index", { - // accounts: accounts - // }) - } - - - - getSubset: function(req, res, next){ + getSubset: function(req, res, next) { Movie.all(function(error, movies) { if(error) { var err = new Error("Error retrieving movies:\n" + error.message) @@ -28,14 +24,11 @@ var MoviesController = { } else { res.json(movies) console.log(res) - - } }) } } - module.exports = MoviesController From 77d40a888c0c4911b38eb2cbb94003c981dd997f Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 17 Jun 2016 13:19:19 -0700 Subject: [PATCH 16/46] changed model to use .sort instead of .all --- app.js | 1 + controllers/movies_controller.js | 53 ++------------------------------ models/movie.js | 40 ++++-------------------- routes/index.js | 6 ++-- 4 files changed, 11 insertions(+), 89 deletions(-) diff --git a/app.js b/app.js index 82374468a..3874867b3 100644 --- a/app.js +++ b/app.js @@ -19,6 +19,7 @@ app.set('views', path.join(__dirname, 'views')) app.set('view engine', 'jade') var routes = require('./routes/index') + var zomgRoutes = require('./routes/zomg') // uncomment after placing your favicon in /public diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index a8b854dfb..2e3e2c781 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -10,70 +10,21 @@ var MoviesController = { next(err) } else { res.json(movies) - console.log(res) } }) }, - getSubset: function(req, res, next) { - Movie.all(function(error, movies) { + sort: function(req, res, next) { + Movie.sort(req.query.n, req.params.column_name, req.query.p, function(error, movies) { if(error) { var err = new Error("Error retrieving movies:\n" + error.message) err.status = 500 next(err) } else { res.json(movies) - console.log(res) } }) } } module.exports = MoviesController - - - - -// res.render("accounts/index", { -// accounts: accounts -// }) - - -// getSubset: function(req, res, next) { -// Movie.all(function(error, movies) { -// if(error) { -// var err = new Error("Error retrieving movies:\n" + error.message) -// err.status = 500 -// next(err) -// } else { -// res.json(movies) -// console.log(res) -// -// // res.render("accounts/index", { -// // accounts: accounts -// // }) -// } -// } -// }) - - - - - // show: function(req, res, next) { - // Account.find(req.params.id, function(error, account) { - // if(error) { - // var err = new Error("No such account") - // err.status = 404 - // next(err) - // } else { - // account.getBalance(function(error, balance) { - // res.render("accounts/show", { - // account: { - // id: account.id, - // balance: balance - // } - // }) - // }) - // } - // }) - // diff --git a/models/movie.js b/models/movie.js index e2dad31a0..cf00276e0 100644 --- a/models/movie.js +++ b/models/movie.js @@ -29,35 +29,14 @@ Movie.all = function(callback) { }) } - - -Movie.prototype.getSubset = function(number, pages, callback) { - var options_release_date = { - number : number, - order : release_date, - offset : pages +Movie.sort = function(n, column_name, p, callback) { + var options = { + limit : n, + order : column_name, + offset : p } - db.movies.find({}, options_release_date, function(err, movies) { - if(error) { - callback(error || new Error("Could not retrieve movies"), undefined) - } else if(!movies) { - callback(error || new Error("No movies found"), undefined) - } else { - callback(null, movies.map(function(movie) { - return new Movie(movie) - })) - } - - }) - - var options_title = { - number : number, - order : title, - offset : pages - } - - db.movies.find({}, options_title, function(err, movies) { + db.movies.find({}, options, function(error, movies) { if(error) { callback(error || new Error("Could not retrieve movies"), undefined) } else if(!movies) { @@ -70,13 +49,6 @@ Movie.prototype.getSubset = function(number, pages, callback) { }) } - - - -// return n movie records, with p (per page) -// sort by release date or by title - - Movie.prototype.getByTitle = function(title, callback) { // get list of customers who are CURRENTLY renting the title // include cust name, phone no, and acct_credit diff --git a/routes/index.js b/routes/index.js index b6f759a69..db470199c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -10,11 +10,9 @@ router.get('/', function(req, res, next) { router.get('/movies', function(req, res, next) { controller.index(req, res, next) }) -//n = number of resultes -//p = page number -router.get('/movies/sort/title?n=:number&p=:pages', function(req, res, next) { - controller.subset(req, res, next) +router.get('/movies/sort/:title', function(req, res, next) { + controller.sort(req, res, next) }) module.exports = router From 1e619995d51fbbc0672486b75f9f41171f313e8c Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 17 Jun 2016 13:54:50 -0700 Subject: [PATCH 17/46] adding routes for customer/rental data --- controllers/movies_controller.js | 12 +++++++++++ models/movie.js | 34 +++++++++++++++++++++++--------- routes/index.js | 4 ++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index 2e3e2c781..4540c2b9c 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -24,6 +24,18 @@ var MoviesController = { res.json(movies) } }) + }, + + getbytitle: function(req, res, next) { + Movie.sort(req.params.title, function(error, movies) { + if(error) { + var err = new Error("Error retrieving movies:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(movies) + } + }) } } diff --git a/models/movie.js b/models/movie.js index cf00276e0..ebaf024d9 100644 --- a/models/movie.js +++ b/models/movie.js @@ -49,25 +49,41 @@ Movie.sort = function(n, column_name, p, callback) { }) } -Movie.prototype.getByTitle = function(title, callback) { +Movie.getbytitle = function(title, callback) { // get list of customers who are CURRENTLY renting the title // include cust name, phone no, and acct_credit // get list of customers who have PAST rented the title -} -var balanceResultCallback = function(movie, callback) { - return function(error, result) { + var options = { + order : column_name + } + + db.movies.find({}, options, function(error, movies) { if(error) { - callback(error, undefined) + callback(error || new Error("Could not retrieve movies"), undefined) + } else if(!movies) { + callback(error || new Error("No movies found"), undefined) } else { - account.getBalance(function(error, balance) { - callback(error, balance) - }) + callback(null, movies.map(function(movie) { + return new Movie(movie) + })) } - } + }) } +// var balanceResultCallback = function(movie, callback) { +// return function(error, result) { +// if(error) { +// callback(error, undefined) +// } else { +// account.getBalance(function(error, balance) { +// callback(error, balance) +// }) +// } +// } +// } + // Movie.prototype.deposit = function(amount, callback) { // db.accounts_deposit(this.id, amount, balanceResultCallback(this, callback)) // return this diff --git a/routes/index.js b/routes/index.js index db470199c..633477c3c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -15,4 +15,8 @@ router.get('/movies/sort/:title', function(req, res, next) { controller.sort(req, res, next) }) +router.get('/movies/getbytitle/:title', function(req, res, next) { + controller.getbytitle(req, res, next) +}) + module.exports = router From 76bfe49fa0a5c9e45c6ca9fc221f248a10202889 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 17 Jun 2016 15:25:36 -0700 Subject: [PATCH 18/46] working on bug in routes --- controllers/customers_controller.js | 43 +++++++++++++++++++ db/seeds/rentals.json | 0 db/setup/schema.sql | 1 + models/customer.js | 64 +++++++++++++++++++++++++++++ routes/index.js | 18 ++++++++ tasks/sql_commands.js | 4 ++ 6 files changed, 130 insertions(+) create mode 100644 db/seeds/rentals.json create mode 100644 tasks/sql_commands.js diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index e69de29bb..30492c3cc 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -0,0 +1,43 @@ +var Customer = require("../models/customer") +console.log("customers") + +var CustomersController = { + + index: function(req, res, next) { + Customer.all(function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + }, + + sort: function(req, res, next) { + Customer.sort(req.query.n, req.params.columns, req.params.column_name, req.query.p, function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + }, + + getbyid: function(req, res, next) { + Customer.sort(req.query.n, req.params.columns, req.params.column_name, req.query.p, function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + } +} + +module.exports = CustomersController diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json new file mode 100644 index 000000000..e69de29bb diff --git a/db/setup/schema.sql b/db/setup/schema.sql index c757a82ef..33f0dba38 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -24,6 +24,7 @@ DROP TABLE IF EXISTS rentals; CREATE TABLE rentals( id serial PRIMARY KEY, movie_id text, + customer_id text, title text, overview text, release_date text, diff --git a/models/customer.js b/models/customer.js index e69de29bb..a3ae3714f 100644 --- a/models/customer.js +++ b/models/customer.js @@ -0,0 +1,64 @@ +var app = require("../app") +var db = app.get('db') + + +var Customer = function(id) { + this.id = id +} + + +Customer.all = function(callback) { + db.customers.find(function(error, customers) { + if(error) { + callback(error || new Error("Could not retrieve customers"), undefined) + } else if(!customers) { + callback(error || new Error("No customers found"), undefined) + } else { + callback(null, customers.map(function(customers) { + return new Customers(customer) + })) + } + }) +} + +Customer.sort = function(n, p, id, name, column_name, callback) { + var options = { + limit : n, + offset : p, + columns : ["name", "registered_at", "postal_code"], + order : column_name + } + + + db.customers.find({}, options, function(error, customers) { + if(error) { + callback(error || new Error("Could not retrieve customers"), undefined) + } else if(!customers) { + callback(error || new Error("No customers found"), undefined) + } else { + callback(null, customers.map(function(customers) { + return new Customers(customer) + })) + } + }) +} + +// Customers.getbyid = function(id, column_name, callback) { +// +// var options = { +// columns : ["id", "name"], +// order : column_name +// } +// +// db.customers.find({}, options, function(error, customers) { +// if(error) { +// callback(error || new Error("Could not retrieve customers"), undefined) +// } else if(!customers) { +// callback(error || new Error("No customers found"), undefined) +// } else { +// callback(null, customers.map(function(customers) { +// return new Customers(customers) +// })) +// } +// }) +// } diff --git a/routes/index.js b/routes/index.js index 633477c3c..39d24885f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -19,4 +19,22 @@ router.get('/movies/getbytitle/:title', function(req, res, next) { controller.getbytitle(req, res, next) }) + +router.get('/customers', function(req, res, next){ + controller.index(req, res, next) + console.log("what") +}) + + +router.get('/customers/sort/:id', function(req, res, next) { + controller.sort(req, res, next) +}) + + +router.get('/customers/getbyid/:id', function(req, res, next) { + controller.getbyid(req, res, next) +}) + + + module.exports = router diff --git a/tasks/sql_commands.js b/tasks/sql_commands.js new file mode 100644 index 000000000..b574de40a --- /dev/null +++ b/tasks/sql_commands.js @@ -0,0 +1,4 @@ +var customersRentalsquery = customers.query('SELECT id, name FROM customers'); + query.on('row',function(row){ + console.log('row.id, row.name') + }); From 01db7bb7472cf25a67b1f35589a9964610671845 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 17 Jun 2016 15:49:53 -0700 Subject: [PATCH 19/46] found missing export, now displaying customers --- app.js | 1 - controllers/customers_controller.js | 1 - models/customer.js | 12 ++++++------ routes/index.js | 21 ++++++++------------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index 3874867b3..81057e3f6 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,6 @@ var bodyParser = require('body-parser') var massive = require('massive') var connectionString = "postgres://localhost/video-store-api" - var app = module.exports = express() var db = massive.connectSync({connectionString : connectionString}) diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index 30492c3cc..e434e62dd 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -1,5 +1,4 @@ var Customer = require("../models/customer") -console.log("customers") var CustomersController = { diff --git a/models/customer.js b/models/customer.js index a3ae3714f..12e036f7d 100644 --- a/models/customer.js +++ b/models/customer.js @@ -1,12 +1,10 @@ var app = require("../app") var db = app.get('db') - var Customer = function(id) { this.id = id } - Customer.all = function(callback) { db.customers.find(function(error, customers) { if(error) { @@ -14,8 +12,8 @@ Customer.all = function(callback) { } else if(!customers) { callback(error || new Error("No customers found"), undefined) } else { - callback(null, customers.map(function(customers) { - return new Customers(customer) + callback(null, customers.map(function(customer) { + return new Customer(customer) })) } }) @@ -36,8 +34,8 @@ Customer.sort = function(n, p, id, name, column_name, callback) { } else if(!customers) { callback(error || new Error("No customers found"), undefined) } else { - callback(null, customers.map(function(customers) { - return new Customers(customer) + callback(null, customers.map(function(customer) { + return new Customer(customer) })) } }) @@ -62,3 +60,5 @@ Customer.sort = function(n, p, id, name, column_name, callback) { // } // }) // } + +module.exports = Customer diff --git a/routes/index.js b/routes/index.js index 39d24885f..112670a80 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,6 +1,7 @@ var express = require('express') var router = express.Router() -var controller = require('../controllers/movies_controller') +var movies_controller = require('../controllers/movies_controller') +var customers_controller = require('../controllers/customers_controller') /* GET home page. */ router.get('/', function(req, res, next) { @@ -8,33 +9,27 @@ router.get('/', function(req, res, next) { }) router.get('/movies', function(req, res, next) { - controller.index(req, res, next) + movies_controller.index(req, res, next) }) router.get('/movies/sort/:title', function(req, res, next) { - controller.sort(req, res, next) + movies_controller.sort(req, res, next) }) router.get('/movies/getbytitle/:title', function(req, res, next) { - controller.getbytitle(req, res, next) + movies_controller.getbytitle(req, res, next) }) - router.get('/customers', function(req, res, next){ - controller.index(req, res, next) - console.log("what") + customers_controller.index(req, res, next) }) - router.get('/customers/sort/:id', function(req, res, next) { - controller.sort(req, res, next) + customers_controller.sort(req, res, next) }) - router.get('/customers/getbyid/:id', function(req, res, next) { - controller.getbyid(req, res, next) + customers_controller.getbyid(req, res, next) }) - - module.exports = router From 87165c8c1026c072f80ea6162be11d30ac2c5d1f Mon Sep 17 00:00:00 2001 From: justine Date: Mon, 20 Jun 2016 11:26:44 -0700 Subject: [PATCH 20/46] have movies and customers sorting correctly --- controllers/customers_controller.js | 2 +- models/customer.js | 4 ++-- models/movie.js | 5 +++-- routes/index.js | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index e434e62dd..9a09fe716 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -15,7 +15,7 @@ var CustomersController = { }, sort: function(req, res, next) { - Customer.sort(req.query.n, req.params.columns, req.params.column_name, req.query.p, function(error, customers) { + Customer.sort(req.params.column_name, req.params.columns, req.query.n, req.query.p, function(error, customers) { if(error) { var err = new Error("Error retrieving customers:\n" + error.message) err.status = 500 diff --git a/models/customer.js b/models/customer.js index 12e036f7d..4c3458b20 100644 --- a/models/customer.js +++ b/models/customer.js @@ -19,7 +19,7 @@ Customer.all = function(callback) { }) } -Customer.sort = function(n, p, id, name, column_name, callback) { +Customer.sort = function(column_name, columns, n, p, callback) { var options = { limit : n, offset : p, @@ -27,7 +27,6 @@ Customer.sort = function(n, p, id, name, column_name, callback) { order : column_name } - db.customers.find({}, options, function(error, customers) { if(error) { callback(error || new Error("Could not retrieve customers"), undefined) @@ -35,6 +34,7 @@ Customer.sort = function(n, p, id, name, column_name, callback) { callback(error || new Error("No customers found"), undefined) } else { callback(null, customers.map(function(customer) { + console.log(customer) return new Customer(customer) })) } diff --git a/models/movie.js b/models/movie.js index ebaf024d9..b1f484298 100644 --- a/models/movie.js +++ b/models/movie.js @@ -29,10 +29,11 @@ Movie.all = function(callback) { }) } -Movie.sort = function(n, column_name, p, callback) { +Movie.sort = function(column_name, n, p, callback) { + console.log(String(column_name)) var options = { - limit : n, order : column_name, + limit : n, offset : p } diff --git a/routes/index.js b/routes/index.js index 112670a80..04a2e9d76 100644 --- a/routes/index.js +++ b/routes/index.js @@ -12,7 +12,7 @@ router.get('/movies', function(req, res, next) { movies_controller.index(req, res, next) }) -router.get('/movies/sort/:title', function(req, res, next) { +router.get('/movies/sort/:column_name', function(req, res, next) { movies_controller.sort(req, res, next) }) @@ -24,7 +24,7 @@ router.get('/customers', function(req, res, next){ customers_controller.index(req, res, next) }) -router.get('/customers/sort/:id', function(req, res, next) { +router.get('/customers/sort/:column_name', function(req, res, next) { customers_controller.sort(req, res, next) }) From 041528071d89b8429b6cc28846b8e8659b3088bc Mon Sep 17 00:00:00 2001 From: justine Date: Mon, 20 Jun 2016 13:11:15 -0700 Subject: [PATCH 21/46] fixing rental seeds --- db/seeds/rentals.json | 82 +++++++++++++++++++++++++++++++++++++++++++ db/setup/schema.sql | 7 ++-- package.json | 2 +- 3 files changed, 85 insertions(+), 6 deletions(-) diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json index e69de29bb..46ba468d1 100644 --- a/db/seeds/rentals.json +++ b/db/seeds/rentals.json @@ -0,0 +1,82 @@ +[ +{ +"movie_id": "1", +"customer_id": "3", +"title": "Psycho", +"checkout_date": "2012-06-18", +"due_date": "2012-06-16", +"returned_date": "2012-06-16" +}, +{ +"movie_id": "3", +"customer_id": "12", +"title": "The Exorcist", +"checkout_date": "2016-06-14", +"due_date": "2016-06-16", +"returned_date": "2016-06-15" +}, +{ +"movie_id": "5", +"customer_id": "9", +"title": "The Silence of the Lambs", +"checkout_date": "2016-04-16", +"due_date": "2016-04-18", +"returned_date": "2016-04-16" +}, +{ +"movie_id": "9", +"customer_id": "28", +"title": "Rosemary's Baby", +"checkout_date": "2011-04-14", +"due_date": "2011-04-16", +"returned_date": "2011-04-16" +}, +{ +"movie_id": "12", +"customer_id": "", +"title": "King Kong", +"checkout_date": "2015-12-08", +"due_date": "2015-12-10", +"returned_date": "2015-12-12" +}, +{ +"movie_id": "14", +"customer_id": "36", +"title": "Rear Window", +"checkout_date": "2015-11-10", +"due_date": "2015-11-12", +"returned_date": "2015-11-13" +}, +{ +"movie_id": "15", +"customer_id": "22", +"title": "Deliverance", +"checkout_date": "2014-02-09", +"due_date": "2014-02-11", +"returned_date": "2014-03-11" +}, +{ +"movie_id": "18", +"customer_id": "22", +"title": "Vertigo", +"checkout_date": "2015-09-28", +"due_date": "2015-09-30", +"returned_date": "2015-10-01" +}, +{ +"movie_id": "20", +"customer_id": "45", +"title": "High Noon", +"checkout_date": "2016-03-02", +"due_date": "2016-03-04", +"returned_date": "2016-03-04" +}, +{ +"movie_id": "25", +"customer_id": "47", +"title": "Titanic", +"checkout_date": "2016-2-14", +"due_date": "2016-2-16", +"returned_date": "2016-2-20" +} +] diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 33f0dba38..ef4a05ec7 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -26,10 +26,7 @@ CREATE TABLE rentals( movie_id text, customer_id text, title text, - overview text, - release_date text, - inventory_available text, - inventory text, checkout_date text, - due_date text + due_date text, + returned_date text ); diff --git a/package.json b/package.json index 544d05ced..a30fac408 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "db:create": "createdb video-store-api", "db:schema": "node tasks/load_schema.js", "db:seed": "node tasks/seed.js", - "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" }, "dependencies": { "body-parser": "~1.13.2", From 3907026c0b662c5212b5e5609ee57181bf82aa32 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 20 Jun 2016 14:28:24 -0700 Subject: [PATCH 22/46] working on getting currently checked out movies --- controllers/customers_controller.js | 16 +++++++++++++ controllers/movies_controller.js | 18 +++++++++++++- controllers/rentals_controller.js | 15 ++++++++++++ models/movie.js | 2 ++ models/rental.js | 37 +++++++++++++++++++++++++++++ routes/index.js | 5 +++- 6 files changed, 91 insertions(+), 2 deletions(-) diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index 9a09fe716..99739922f 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -1,4 +1,5 @@ var Customer = require("../models/customer") +var Rental = require("../models/rental") var CustomersController = { @@ -36,7 +37,22 @@ var CustomersController = { res.json(customers) } }) + }, + + current: function(req, res, next) { + Rental.current(req.query.n,req.query.p, req.params.column_name, req.params.columns, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) } + + + } module.exports = CustomersController diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index 4540c2b9c..f554e0748 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -36,7 +36,23 @@ var MoviesController = { res.json(movies) } }) - } + }, + + currently_checkout: function(req, res, next) { + Rental.sort(req.params.name, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + }, + + + + } module.exports = MoviesController diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js index e69de29bb..1b1526041 100644 --- a/controllers/rentals_controller.js +++ b/controllers/rentals_controller.js @@ -0,0 +1,15 @@ +var Rental = require("../models/rental") + +var RentalsController = { + + currently_checkout: function(req, res, next) { + Rental.all(function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + }, diff --git a/models/movie.js b/models/movie.js index b1f484298..41935c239 100644 --- a/models/movie.js +++ b/models/movie.js @@ -73,6 +73,8 @@ Movie.getbytitle = function(title, callback) { }) } + + // var balanceResultCallback = function(movie, callback) { // return function(error, result) { // if(error) { diff --git a/models/rental.js b/models/rental.js index e69de29bb..be9c5f726 100644 --- a/models/rental.js +++ b/models/rental.js @@ -0,0 +1,37 @@ +var app = require("../app") +var db = app.get('db') + +// Constructor function +var Rental = function(id) { + this.id = id +} + +Rental.current = function(n, p, column_name, columns, callback) { + var options = { + limit : n, + offset : p, + columns : ["title"], + order : column_name + } + + db.rentals.find({ + or: [{ + "customer_id =" :req.params.columns["customer_id"], + "returned_date =": null + + + }] + }, options, function(error, rental) { + if(error) { + callback(error || new Error("Could not retrieve checket out rentals"), undefined) + } else if(!rentals) { + callback(error || new Error("No checked out rentals found"), undefined) + } else { + callback(null, rentals.map(function(rental) { + return new Rental(rental) + })) + } + }) +} + +module.exports = Rental diff --git a/routes/index.js b/routes/index.js index 04a2e9d76..ebbf823f6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -28,8 +28,11 @@ router.get('/customers/sort/:column_name', function(req, res, next) { customers_controller.sort(req, res, next) }) -router.get('/customers/getbyid/:id', function(req, res, next) { +router.get('/customers/getbyid/:id', function(req, res, next){ customers_controller.getbyid(req, res, next) }) +router.get('/customers/:id/current', function(req,res,next){ + customers_controller.current(req,res,next) +}) module.exports = router From c2107457a161a3894de3f599df6429b438f07b7d Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 20 Jun 2016 14:40:42 -0700 Subject: [PATCH 23/46] fixing empty array but for currently checked out movies --- db/seeds/rentals.json | 8 ++++---- models/rental.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json index 46ba468d1..13664fd31 100644 --- a/db/seeds/rentals.json +++ b/db/seeds/rentals.json @@ -13,7 +13,7 @@ "title": "The Exorcist", "checkout_date": "2016-06-14", "due_date": "2016-06-16", -"returned_date": "2016-06-15" +"returned_date": null }, { "movie_id": "5", @@ -29,7 +29,7 @@ "title": "Rosemary's Baby", "checkout_date": "2011-04-14", "due_date": "2011-04-16", -"returned_date": "2011-04-16" +"returned_date": null }, { "movie_id": "12", @@ -45,7 +45,7 @@ "title": "Rear Window", "checkout_date": "2015-11-10", "due_date": "2015-11-12", -"returned_date": "2015-11-13" +"returned_date": null }, { "movie_id": "15", @@ -53,7 +53,7 @@ "title": "Deliverance", "checkout_date": "2014-02-09", "due_date": "2014-02-11", -"returned_date": "2014-03-11" +"returned_date": null }, { "movie_id": "18", diff --git a/models/rental.js b/models/rental.js index be9c5f726..c812ea04d 100644 --- a/models/rental.js +++ b/models/rental.js @@ -16,12 +16,12 @@ Rental.current = function(n, p, column_name, columns, callback) { db.rentals.find({ or: [{ - "customer_id =" :req.params.columns["customer_id"], + // "customer_id =" :req.params.columns["customer_id"], "returned_date =": null }] - }, options, function(error, rental) { + }, options, function(error, rentals) { if(error) { callback(error || new Error("Could not retrieve checket out rentals"), undefined) } else if(!rentals) { From 01932510d32f32f8864d7d5e6b48cf770a0bc9b5 Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 21 Jun 2016 09:40:43 -0700 Subject: [PATCH 24/46] took out comments, finally have current retals path working --- controllers/customers_controller.js | 8 ++- db/rental.sql | 14 +++++ models/customer.js | 22 +------- models/movie.js | 80 ----------------------------- models/rental.js | 26 ++-------- tasks/db_drop.js | 1 + tasks/seed.js | 6 +++ 7 files changed, 29 insertions(+), 128 deletions(-) create mode 100644 db/rental.sql diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index 99739922f..9521f07eb 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -40,9 +40,10 @@ var CustomersController = { }, current: function(req, res, next) { - Rental.current(req.query.n,req.query.p, req.params.column_name, req.params.columns, function(error, rentals) { + // console.log(req.params.id) + Rental.current(req.params.id, function(error, rentals) { if(error) { - var err = new Error("Error retrieving rentals:\n" + error.message) + var err = new Error("Error retrieving rentals" + error.message) err.status = 500 next(err) } else { @@ -50,9 +51,6 @@ var CustomersController = { } }) } - - - } module.exports = CustomersController diff --git a/db/rental.sql b/db/rental.sql new file mode 100644 index 000000000..07102b85f --- /dev/null +++ b/db/rental.sql @@ -0,0 +1,14 @@ +-- select title, movie id, where customer_id = params.id +-- make sql file in db +-- queries in that file create js-accessible functions- use them in the model. + +-- SELECT movie_id, title +-- FROM rentals +-- WHERE customer_id=(SELECT id FROM movies WHERE customer_id=$1) AND returned=false", [movie_title] +-- +-- List the movies they currently have checked out (/customers/5/current) +-- List the movies a customer has checked out in the past (/customers/5/history) +-- ordered by check out date +-- includes return date + +db.run("SELECT * FROM rentals;") diff --git a/models/customer.js b/models/customer.js index 4c3458b20..a0731f9e2 100644 --- a/models/customer.js +++ b/models/customer.js @@ -34,31 +34,11 @@ Customer.sort = function(column_name, columns, n, p, callback) { callback(error || new Error("No customers found"), undefined) } else { callback(null, customers.map(function(customer) { - console.log(customer) + // console.log(customer) return new Customer(customer) })) } }) } -// Customers.getbyid = function(id, column_name, callback) { -// -// var options = { -// columns : ["id", "name"], -// order : column_name -// } -// -// db.customers.find({}, options, function(error, customers) { -// if(error) { -// callback(error || new Error("Could not retrieve customers"), undefined) -// } else if(!customers) { -// callback(error || new Error("No customers found"), undefined) -// } else { -// callback(null, customers.map(function(customers) { -// return new Customers(customers) -// })) -// } -// }) -// } - module.exports = Customer diff --git a/models/movie.js b/models/movie.js index 41935c239..81661ad00 100644 --- a/models/movie.js +++ b/models/movie.js @@ -30,7 +30,6 @@ Movie.all = function(callback) { } Movie.sort = function(column_name, n, p, callback) { - console.log(String(column_name)) var options = { order : column_name, limit : n, @@ -73,83 +72,4 @@ Movie.getbytitle = function(title, callback) { }) } - - -// var balanceResultCallback = function(movie, callback) { -// return function(error, result) { -// if(error) { -// callback(error, undefined) -// } else { -// account.getBalance(function(error, balance) { -// callback(error, balance) -// }) -// } -// } -// } - -// Movie.prototype.deposit = function(amount, callback) { -// db.accounts_deposit(this.id, amount, balanceResultCallback(this, callback)) -// return this -// } -// -// Movie.prototype.withdraw = function(amount, callback) { -// db.accounts_withdraw(this.id, amount, balanceResultCallback(this, callback)) -// return this -// } -// -// Movie.prototype.transfer = function(to, amount, callback) { -// db.accounts_transfer(this.id, to.id, amount, balanceResultCallback(this, callback)) -// return this -// } -// -// // Class Functions -// Movie.create = function(initialBalance, callback) { -// db.accounts.save({ -// balance: initialBalance -// }, function(error, account) { -// if(error || !account) { -// callback(error || new Error("Could not create account"), undefined) -// } else { -// callback(null, new Movie(account.id)) -// } -// }) -// } -// -// Movie.createSync = function(initialBalance) { -// var account = db.accounts.saveSync({ -// balance: initialBalance -// }) -// -// return new Movie(account.id) -// } -// -// Movie.all = function(callback) { -// db.accounts.find(function(error, accounts) { -// if(error || !accounts) { -// callback(error || new Error("Could not retrieve accounts"), undefined) -// } else { -// callback(null, accounts.map(function(account) { -// return new Movie(account.id) -// })) -// } -// }) -// } -// -// Movie.find = function(id, callback) { -// db.accounts.findOne({id: id}, function(error, account) { -// if(error || !account) { -// callback(error || new Error("Movie not found"), undefined) -// } else { -// callback(null, new Movie(account.id)) -// } -// }) -// } -// -// // only attach this function if we're in test mode -// if (app.get('env') === 'test') { -// Movie.close_connection = function() { -// console.log("closing connection") -// db.end() -// } -// } module.exports = Movie diff --git a/models/rental.js b/models/rental.js index c812ea04d..cbd3134a0 100644 --- a/models/rental.js +++ b/models/rental.js @@ -6,30 +6,12 @@ var Rental = function(id) { this.id = id } -Rental.current = function(n, p, column_name, columns, callback) { - var options = { - limit : n, - offset : p, - columns : ["title"], - order : column_name - } - - db.rentals.find({ - or: [{ - // "customer_id =" :req.params.columns["customer_id"], - "returned_date =": null - - - }] - }, options, function(error, rentals) { +Rental.current = function(customer_id, callback) { + db.run("select * from rentals where customer_id = $1", [customer_id], function(error, rentals){ if(error) { - callback(error || new Error("Could not retrieve checket out rentals"), undefined) - } else if(!rentals) { - callback(error || new Error("No checked out rentals found"), undefined) + callback(error, undefined); } else { - callback(null, rentals.map(function(rental) { - return new Rental(rental) - })) + callback(null, rentals); } }) } diff --git a/tasks/db_drop.js b/tasks/db_drop.js index 5ca18b05b..1bbbdc053 100644 --- a/tasks/db_drop.js +++ b/tasks/db_drop.js @@ -6,6 +6,7 @@ db.setup.schema([],function(err,res)){ if(err){ } throw(new Error(err.message)) } + console.log(“yay schema!”) process.exit() }) diff --git a/tasks/seed.js b/tasks/seed.js index 1a9ca57d2..678bfdefa 100644 --- a/tasks/seed.js +++ b/tasks/seed.js @@ -3,6 +3,7 @@ var connectionString = 'postgres://localhost/video-store-api' var db = massive.connectSync({connectionString : connectionString}) var movies = require('../db/seeds/movies.json') var customers = require('../db/seeds/customers.json') +var rentals = require('../db/seeds/rentals.json') for (var movie of movies) { console.log(movie) @@ -14,4 +15,9 @@ for (var customer of customers) { db.customers.saveSync(customer) } +for (var rental of rentals) { + console.log(rental) + db.rentals.saveSync(rental) +} + process.exit() From 638350a657932a626689194f1cedbd3e2b222765 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 21 Jun 2016 12:58:15 -0700 Subject: [PATCH 25/46] first three passing test --- spec/controllers/customers.spec.js | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/controllers/customers.spec.js diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js new file mode 100644 index 000000000..ea7dc0b30 --- /dev/null +++ b/spec/controllers/customers.spec.js @@ -0,0 +1,37 @@ +var request = require('request') +var base_url = "http://localhost:3000/customers" + + +describe("Endpoint at /customers", function () { + // it('responds with a 200 status code', function (done) { + // request.get(base_url, function(error, response, body) { + // expect(response.statusCode).toEqual(200) + // done() + // }) + // }) + + describe("the returned json data", function() { + it('has the right keys', function(done) { + request.get(base_url, function(error, response, body) { + var customers = JSON.parse(body)[0]["id"] + expect(Object.keys(customers)).toEqual(['id','name','registered_at', 'address', 'city', 'state', 'postal_code', 'phone', 'account_credit']) + done() + }) + }) + + // it('has the right values for the keys', function(done) { + // request.get(base_url, function(error, response, body) { + // var data = JSON.parse(body) + // expect(data.whatevs).toEqual('whatevs!!!') + // done() + // }) + // }) + }) + + + + + + + +}) From 3786ba81c3d7dc4bf588ba913b4f471cf22c29a7 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 21 Jun 2016 13:13:35 -0700 Subject: [PATCH 26/46] passing test has the right values for the keys --- spec/controllers/customers.spec.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index ea7dc0b30..31b22fff4 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -19,19 +19,13 @@ describe("Endpoint at /customers", function () { }) }) - // it('has the right values for the keys', function(done) { - // request.get(base_url, function(error, response, body) { - // var data = JSON.parse(body) - // expect(data.whatevs).toEqual('whatevs!!!') - // done() - // }) - // }) + it('has the right values for the keys', function(done) { + request.get(base_url, function(error, response, body) { + var customers = JSON.parse(body)[0]["id"] + expect(customers.name).toEqual('Shelley Rocha') + done() + }) + }) }) - - - - - - }) From bb6e54d2fd5e7fc9887cb64ed70147dfbb6eee24 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 21 Jun 2016 15:33:21 -0700 Subject: [PATCH 27/46] Get a list of customers that have checked out a copy in the past --- controllers/movies_controller.js | 16 +++++++++++++++- models/customer.js | 26 +++++++++++++++++++++++++ models/rental.js | 33 +++++++++++++++++++++++++++++++- package.json | 5 ++++- routes/index.js | 5 +++++ 5 files changed, 82 insertions(+), 3 deletions(-) diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index f554e0748..9109271ed 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -1,4 +1,5 @@ var Movie = require("../models/movie") +var Rental = require("../models/rental") var MoviesController = { @@ -37,7 +38,6 @@ var MoviesController = { } }) }, - currently_checkout: function(req, res, next) { Rental.sort(req.params.name, function(error, rentals) { if(error) { @@ -50,6 +50,20 @@ var MoviesController = { }) }, + history: function(req, res, next) { + Rental.history(req.params.title, req.params.column_name, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + } + + + diff --git a/models/customer.js b/models/customer.js index a0731f9e2..e47a3e408 100644 --- a/models/customer.js +++ b/models/customer.js @@ -41,4 +41,30 @@ Customer.sort = function(column_name, columns, n, p, callback) { }) } +Customer.find_id = function(customer_ids, column_name, columns) { + var options = { + order : column_name, + columns : ['name', 'phone', 'account_credit'] + } + + db.customers.find({}, options, function(error, customer) { + // if(error) { + // callback(error || new Error("Could not retrieve customers"), undefined) + // } else if(!customers) { + // callback(error || new Error("No customers found"), undefined) + // } else { + // callback(null, customers.map(function(customer) { + console.log(customer) + return new Customer(customer) + // })) + // } + }) + + + + + +} + + module.exports = Customer diff --git a/models/rental.js b/models/rental.js index cbd3134a0..3176cbfe0 100644 --- a/models/rental.js +++ b/models/rental.js @@ -1,11 +1,15 @@ var app = require("../app") +var Customer = require("../models/customer") var db = app.get('db') - // Constructor function var Rental = function(id) { this.id = id } +// var Customer = function(id){ +// this.id = id +// } + Rental.current = function(customer_id, callback) { db.run("select * from rentals where customer_id = $1", [customer_id], function(error, rentals){ if(error) { @@ -16,4 +20,31 @@ Rental.current = function(customer_id, callback) { }) } +Rental.history = function(title, column_name, callback) { + db.run("SELECT * FROM customers WHERE CAST(id AS text)= (select customer_id from rentals where title = $1)", [title], function(error, customer_ids){ + if(error) { + callback(error, undefined); + } else { + Customer.find_id(customer_ids, column_name) + callback(null, customer_ids); + // console.log("customer ids: " + customer_ids[0]["customer_id"]) + } + }) + +} + + +// Rental.getCustomers = function(movie_title, callback) { +// db.run("SELECT * FROM customers WHERE id=(SELECT customer_id FROM rentals WHERE movie_id=(SELECT id FROM movies WHERE title=$1) AND returned=false)", [movie_title], function(error, customers) { +// if(error) { +// callback(error, undefined); +// } else { +// callback(null, customers); +// } +// }) +// } + + + + module.exports = Rental diff --git a/package.json b/package.json index a30fac408..579cae322 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,17 @@ "db:create": "createdb video-store-api", "db:schema": "node tasks/load_schema.js", "db:seed": "node tasks/seed.js", - "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", + "test": "istanbul cover --include-all-sources jasmine-node test" }, "dependencies": { "body-parser": "~1.13.2", "cookie-parser": "~1.3.5", "debug": "~2.2.0", "express": "~4.13.1", + "istanbul": "^0.4.4", "jade": "~1.11.0", + "jasmine-node": "^1.14.5", "massive": "^2.3.0", "morgan": "~1.6.1", "serve-favicon": "~2.3.0" diff --git a/routes/index.js b/routes/index.js index ebbf823f6..9ca9fbe4d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -35,4 +35,9 @@ router.get('/customers/getbyid/:id', function(req, res, next){ router.get('/customers/:id/current', function(req,res,next){ customers_controller.current(req,res,next) }) + + +router.get('/movies/:title/history/sort/:column_name',function(req,res,next){ + movies_controller.history(req,res,next) +}) module.exports = router From 08d30df5d912e5b8d59c421a5eba9ee06b82c079 Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 21 Jun 2016 16:20:32 -0700 Subject: [PATCH 28/46] got history endpoint working, cleaning up comments, had to edit seeds. --- controllers/customers_controller.js | 1 - db/seeds/rentals.json | 10 +++++----- models/customer.js | 2 +- models/rental.js | 30 +++++------------------------ 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index 9521f07eb..9121e9e21 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -40,7 +40,6 @@ var CustomersController = { }, current: function(req, res, next) { - // console.log(req.params.id) Rental.current(req.params.id, function(error, rentals) { if(error) { var err = new Error("Error retrieving rentals" + error.message) diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json index 13664fd31..47570978c 100644 --- a/db/seeds/rentals.json +++ b/db/seeds/rentals.json @@ -16,9 +16,9 @@ "returned_date": null }, { -"movie_id": "5", +"movie_id": "1", "customer_id": "9", -"title": "The Silence of the Lambs", +"title": "Psycho", "checkout_date": "2016-04-16", "due_date": "2016-04-18", "returned_date": "2016-04-16" @@ -32,9 +32,9 @@ "returned_date": null }, { -"movie_id": "12", -"customer_id": "", -"title": "King Kong", +"movie_id": "1", +"customer_id": "36", +"title": "Psycho", "checkout_date": "2015-12-08", "due_date": "2015-12-10", "returned_date": "2015-12-12" diff --git a/models/customer.js b/models/customer.js index e47a3e408..1f3f61c6d 100644 --- a/models/customer.js +++ b/models/customer.js @@ -54,7 +54,7 @@ Customer.find_id = function(customer_ids, column_name, columns) { // callback(error || new Error("No customers found"), undefined) // } else { // callback(null, customers.map(function(customer) { - console.log(customer) + // console.log(customer) return new Customer(customer) // })) // } diff --git a/models/rental.js b/models/rental.js index 3176cbfe0..7cd2e2ccf 100644 --- a/models/rental.js +++ b/models/rental.js @@ -6,45 +6,25 @@ var Rental = function(id) { this.id = id } -// var Customer = function(id){ -// this.id = id -// } - Rental.current = function(customer_id, callback) { db.run("select * from rentals where customer_id = $1", [customer_id], function(error, rentals){ if(error) { - callback(error, undefined); + callback(error, undefined) } else { - callback(null, rentals); + callback(null, rentals) } }) } Rental.history = function(title, column_name, callback) { - db.run("SELECT * FROM customers WHERE CAST(id AS text)= (select customer_id from rentals where title = $1)", [title], function(error, customer_ids){ + db.run("select name, phone, account_credit FROM customers WHERE id IN (select customer_id::int FROM rentals WHERE title = $1)", [title], function(error, customer_ids){ if(error) { - callback(error, undefined); + callback(error, undefined) } else { Customer.find_id(customer_ids, column_name) - callback(null, customer_ids); - // console.log("customer ids: " + customer_ids[0]["customer_id"]) + callback(null, customer_ids) } }) - } - -// Rental.getCustomers = function(movie_title, callback) { -// db.run("SELECT * FROM customers WHERE id=(SELECT customer_id FROM rentals WHERE movie_id=(SELECT id FROM movies WHERE title=$1) AND returned=false)", [movie_title], function(error, customers) { -// if(error) { -// callback(error, undefined); -// } else { -// callback(null, customers); -// } -// }) -// } - - - - module.exports = Rental From 5ed8e2948efb1f379051474b91322dfba472c94d Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 22 Jun 2016 13:11:38 -0700 Subject: [PATCH 29/46] removed comments, unused routes, unused functions. all endpoints for movies & customers working. --- controllers/customers_controller.js | 14 +++++------ controllers/movies_controller.js | 25 ++++--------------- models/customer.js | 5 ---- models/movie.js | 33 ------------------------- models/rental.js | 37 +++++++++++++++++++++++++---- routes/index.js | 22 ++++++++++------- 6 files changed, 56 insertions(+), 80 deletions(-) diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js index 9121e9e21..9f37e43fe 100644 --- a/controllers/customers_controller.js +++ b/controllers/customers_controller.js @@ -27,22 +27,22 @@ var CustomersController = { }) }, - getbyid: function(req, res, next) { - Customer.sort(req.query.n, req.params.columns, req.params.column_name, req.query.p, function(error, customers) { + current: function(req, res, next) { + Rental.current_id(req.params.id, req.params.column_name, function(error, rentals) { if(error) { - var err = new Error("Error retrieving customers:\n" + error.message) + var err = new Error("Error retrieving rentals" + error.message) err.status = 500 next(err) } else { - res.json(customers) + res.json(rentals) } }) }, - current: function(req, res, next) { - Rental.current(req.params.id, function(error, rentals) { + history: function(req, res, next) { + Rental.history_cust_id(req.params.id, req.params.column_name, req.params.column, function(error, rentals) { if(error) { - var err = new Error("Error retrieving rentals" + error.message) + var err = new Error("Error retrieving rentals:\n" + error.message) err.status = 500 next(err) } else { diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js index 9109271ed..17ee9fc4c 100644 --- a/controllers/movies_controller.js +++ b/controllers/movies_controller.js @@ -16,7 +16,7 @@ var MoviesController = { }, sort: function(req, res, next) { - Movie.sort(req.query.n, req.params.column_name, req.query.p, function(error, movies) { + Movie.sort(req.params.column_name, req.query.n, req.query.p, function(error, movies) { if(error) { var err = new Error("Error retrieving movies:\n" + error.message) err.status = 500 @@ -27,19 +27,8 @@ var MoviesController = { }) }, - getbytitle: function(req, res, next) { - Movie.sort(req.params.title, function(error, movies) { - if(error) { - var err = new Error("Error retrieving movies:\n" + error.message) - err.status = 500 - next(err) - } else { - res.json(movies) - } - }) - }, - currently_checkout: function(req, res, next) { - Rental.sort(req.params.name, function(error, rentals) { + current: function(req, res, next) { + Rental.current_title(req.params.title, req.params.columns, function(error, rentals) { if(error) { var err = new Error("Error retrieving rentals:\n" + error.message) err.status = 500 @@ -51,7 +40,7 @@ var MoviesController = { }, history: function(req, res, next) { - Rental.history(req.params.title, req.params.column_name, function(error, rentals) { + Rental.history_title(req.params.title, req.params.column_name, function(error, rentals) { if(error) { var err = new Error("Error retrieving rentals:\n" + error.message) err.status = 500 @@ -61,12 +50,6 @@ var MoviesController = { } }) } - - - - - - } module.exports = MoviesController diff --git a/models/customer.js b/models/customer.js index 1f3f61c6d..d5bfc56f0 100644 --- a/models/customer.js +++ b/models/customer.js @@ -59,11 +59,6 @@ Customer.find_id = function(customer_ids, column_name, columns) { // })) // } }) - - - - - } diff --git a/models/movie.js b/models/movie.js index 81661ad00..989e02b11 100644 --- a/models/movie.js +++ b/models/movie.js @@ -1,20 +1,10 @@ var app = require("../app") var db = app.get('db') -// Constructor function var Movie = function(id) { this.id = id } -// Instance functions -// get a list of all movies /movies -// get a subset of movies - sort by release date or by title -// return n movie records, with p (per page) -// given a title, get list of customers who are CURRENTLY renting the title -// include cust name, phone no, and acct_credit -// get list of customers who have rented title in the past - sort by cust name or checkout_date -// include cust name, phone no, and acct_credit - Movie.all = function(callback) { db.movies.find(function(error, movies) { if(error) { @@ -49,27 +39,4 @@ Movie.sort = function(column_name, n, p, callback) { }) } -Movie.getbytitle = function(title, callback) { -// get list of customers who are CURRENTLY renting the title -// include cust name, phone no, and acct_credit - -// get list of customers who have PAST rented the title - - var options = { - order : column_name - } - - db.movies.find({}, options, function(error, movies) { - if(error) { - callback(error || new Error("Could not retrieve movies"), undefined) - } else if(!movies) { - callback(error || new Error("No movies found"), undefined) - } else { - callback(null, movies.map(function(movie) { - return new Movie(movie) - })) - } - }) -} - module.exports = Movie diff --git a/models/rental.js b/models/rental.js index 7cd2e2ccf..f0ae2eac4 100644 --- a/models/rental.js +++ b/models/rental.js @@ -6,18 +6,45 @@ var Rental = function(id) { this.id = id } -Rental.current = function(customer_id, callback) { - db.run("select * from rentals where customer_id = $1", [customer_id], function(error, rentals){ +Rental.current_title = function(title, columns, callback) { + var options = { + columns : ['name', 'phone', 'account_credit'] + } + db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (select customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers){ if(error) { callback(error, undefined) } else { - callback(null, rentals) + callback(null, customers) } }) } -Rental.history = function(title, column_name, callback) { - db.run("select name, phone, account_credit FROM customers WHERE id IN (select customer_id::int FROM rentals WHERE title = $1)", [title], function(error, customer_ids){ +Rental.current_id = function(id, column_name, callback) { + var options = { + order : column_name + } + db.run("SELECT title FROM movies WHERE title IN (select title FROM rentals WHERE customer_id::int = $1 AND returned_date IS null)", [id], function(error, movies){ + if(error) { + callback(error, undefined) + } else { + callback(null, movies) + } + }) +} + +Rental.history_title = function(title, column_name, callback) { + db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (select customer_id::int FROM rentals WHERE title = $1 AND returned_date IS NOT null)", [title], function(error, customer_ids){ + if(error) { + callback(error, undefined) + } else { + Customer.find_id(customer_ids, column_name) + callback(null, customer_ids) + } + }) +} + +Rental.history_cust_id = function(id, column_name, columns, callback) { + db.run("SELECT title FROM rentals WHERE customer_id = $1 AND returned_date IS NOT null", [id], function(error, customer_ids){ if(error) { callback(error, undefined) } else { diff --git a/routes/index.js b/routes/index.js index 9ca9fbe4d..77acc762d 100644 --- a/routes/index.js +++ b/routes/index.js @@ -16,8 +16,13 @@ router.get('/movies/sort/:column_name', function(req, res, next) { movies_controller.sort(req, res, next) }) -router.get('/movies/getbytitle/:title', function(req, res, next) { - movies_controller.getbytitle(req, res, next) +router.get('/movies/:title/current', +function(req, res, next) { + movies_controller.current(req, res, next) +}) + +router.get('/movies/:title/history/sort/:column_name',function(req, res, next){ + movies_controller.history(req, res, next) }) router.get('/customers', function(req, res, next){ @@ -28,16 +33,15 @@ router.get('/customers/sort/:column_name', function(req, res, next) { customers_controller.sort(req, res, next) }) -router.get('/customers/getbyid/:id', function(req, res, next){ - customers_controller.getbyid(req, res, next) +router.get('/customers/:id/current', function(req, res, next){ + customers_controller.current(req, res, next) }) -router.get('/customers/:id/current', function(req,res,next){ - customers_controller.current(req,res,next) +// TO DO: +router.get('/customers/:id/history', +function(req, res, next) { + customers_controller.history(req, res, next) }) -router.get('/movies/:title/history/sort/:column_name',function(req,res,next){ - movies_controller.history(req,res,next) -}) module.exports = router From 2a4118e52e0ea50b6951ce792bd036b2f9a637a7 Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 22 Jun 2016 13:19:53 -0700 Subject: [PATCH 30/46] creating rentals routes --- routes/index.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/routes/index.js b/routes/index.js index 77acc762d..c0e3272c6 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,7 +3,6 @@ var router = express.Router() var movies_controller = require('../controllers/movies_controller') var customers_controller = require('../controllers/customers_controller') -/* GET home page. */ router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) }) @@ -37,11 +36,37 @@ router.get('/customers/:id/current', function(req, res, next){ customers_controller.current(req, res, next) }) -// TO DO: router.get('/customers/:id/history', function(req, res, next) { customers_controller.history(req, res, next) }) +//TO DO +router.get('/rentals/:title', +function(req, res, next) { + rentals_controller.view(req, res, next) +}) + +router.get('/rentals/:title/customers', +function(req, res, next) { + rentals_controller.customers(req, res, next) +}) + +router.get('/rentals/:title/check-out/:id', +function(req, res, next) { + rentals_controller.check-out(req, res, next) +}) + +router.get('/rentals/:title/return/:id', +function(req, res, next) { + rentals_controller.return(req, res, next) +}) + +router.get('/rentals/overdue', +function(req, res, next) { + rentals_controller.overdue(req, res, next) +}) + + module.exports = router From 12a807f5a753f5d401c2f9d3e0ca496b5ab4a5ff Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 22 Jun 2016 13:20:28 -0700 Subject: [PATCH 31/46] working on testing --- spec/controllers/customers.spec.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 31b22fff4..24c5d3505 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -3,12 +3,12 @@ var base_url = "http://localhost:3000/customers" describe("Endpoint at /customers", function () { - // it('responds with a 200 status code', function (done) { - // request.get(base_url, function(error, response, body) { - // expect(response.statusCode).toEqual(200) - // done() - // }) - // }) + it('responds with a 200 status code', function (done) { + request.get(base_url, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }) describe("the returned json data", function() { it('has the right keys', function(done) { @@ -28,4 +28,20 @@ describe("Endpoint at /customers", function () { }) }) + + describe("#index", function(){ + it ("returns a Success response", function(done){ + request.get(base_url("/customers"), function(error,response,body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + }) + + + + + + + }) From c7231d22a89667cbf053609f5a042de1bce52edf Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 23 Jun 2016 13:57:40 -0700 Subject: [PATCH 32/46] rentals view function working --- controllers/rentals_controller.js | 39 ++++++++++++++++++++++++++----- models/rental.js | 21 +++++++++++++---- routes/index.js | 1 + 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js index 1b1526041..2afd76055 100644 --- a/controllers/rentals_controller.js +++ b/controllers/rentals_controller.js @@ -1,15 +1,42 @@ var Rental = require("../models/rental") +var Movie = require("../models/movie") +var Customer = require("../models/customer") var RentalsController = { - - currently_checkout: function(req, res, next) { - Rental.all(function(error, rentals) { + view: function(req, res, next) { + Rental.view(req.params.title, function(error, movies) { if(error) { - var err = new Error("Error retrieving rentals:\n" + error.message) + var err = new Error("Error retrieving movies:\n" + error.message) err.status = 500 next(err) } else { - res.json(rentals) + // console.log(res.json(movies)) + res.json(movies) } }) - }, + } + +// getRentals: function(req, res) { +// Movie.findMovie(req.params.title, function(error, movie) { +// if(error) { +// var err = new Error("No such movie"); +// err.status = 404; +// } else { +// Rental.getCurrentlyCheckedOut(movie, function(error, checked_out) { +// var return_data = { +// title:movie.title, +// overview:movie.overview, +// release_date:movie.release_date, +// total_inventory:movie.inventory, +// available_copies:(parseInt(movie.inventory))-(parseInt(checked_out)) +// } +// res.json(return_data) +// }) +// } +// ​ +// }) +// }, + +} + +module.exports = RentalsController diff --git a/models/rental.js b/models/rental.js index f0ae2eac4..9dc7c5189 100644 --- a/models/rental.js +++ b/models/rental.js @@ -1,16 +1,29 @@ var app = require("../app") var Customer = require("../models/customer") +var Movie = require("../models/movie") var db = app.get('db') // Constructor function var Rental = function(id) { this.id = id } +Rental.view = function(title, callback) { + db.run("SELECT overview, release_date FROM movies WHERE title IN (SELECT title FROM rentals where title = $1 AND returned_date IS null)", [title], function(error, rentals) { + // console.log("rentals: " + JSON.stringify(rentals)) + // console.log("error: " + error) + if(error) { + callback(error, undefined) + } else { + callback(null, rentals) + } + }) +} + Rental.current_title = function(title, columns, callback) { var options = { columns : ['name', 'phone', 'account_credit'] } - db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (select customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers){ + db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers) { if(error) { callback(error, undefined) } else { @@ -23,7 +36,7 @@ Rental.current_id = function(id, column_name, callback) { var options = { order : column_name } - db.run("SELECT title FROM movies WHERE title IN (select title FROM rentals WHERE customer_id::int = $1 AND returned_date IS null)", [id], function(error, movies){ + db.run("SELECT title FROM movies WHERE title IN (SELECT title FROM rentals WHERE customer_id::int = $1 AND returned_date IS null)", [id], function(error, movies) { if(error) { callback(error, undefined) } else { @@ -33,7 +46,7 @@ Rental.current_id = function(id, column_name, callback) { } Rental.history_title = function(title, column_name, callback) { - db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (select customer_id::int FROM rentals WHERE title = $1 AND returned_date IS NOT null)", [title], function(error, customer_ids){ + db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS NOT null)", [title], function(error, customer_ids) { if(error) { callback(error, undefined) } else { @@ -44,7 +57,7 @@ Rental.history_title = function(title, column_name, callback) { } Rental.history_cust_id = function(id, column_name, columns, callback) { - db.run("SELECT title FROM rentals WHERE customer_id = $1 AND returned_date IS NOT null", [id], function(error, customer_ids){ + db.run("SELECT title FROM rentals WHERE customer_id = $1 AND returned_date IS NOT null", [id], function(error, customer_ids) { if(error) { callback(error, undefined) } else { diff --git a/routes/index.js b/routes/index.js index c0e3272c6..beb681b0c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -2,6 +2,7 @@ var express = require('express') var router = express.Router() var movies_controller = require('../controllers/movies_controller') var customers_controller = require('../controllers/customers_controller') +var rentals_controller = require('../controllers/rentals_controller') router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) From 2eff470b71b5be3200e814964cfd4b15d97482a8 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 23 Jun 2016 14:29:52 -0700 Subject: [PATCH 33/46] I am going to change the format of the controller test --- spec/controllers/customers.spec.js | 23 ++++++++------- spec/controllers/movies.spec.js | 45 ++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 24c5d3505..043a9f5d7 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -26,22 +26,21 @@ describe("Endpoint at /customers", function () { done() }) }) - }) + it('Endpoint at customers/15/current', function(done){ + request.get("http://localhost:3000/customers/45/current", function(error,response, body){ + var customers = JSON.parse(body) + expect(response.statusCode).toEqual(200) + done() + }) + }) - describe("#index", function(){ - it ("returns a Success response", function(done){ - request.get(base_url("/customers"), function(error,response,body){ - expect(response.statusCode).toBe(200) + it('should be an array of objects', function(done){ + request.get(base_url,function(error,response,body){ + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') done() }) }) }) - - - - - - - }) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index ddcaf2f68..7f64967fa 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,5 +1,44 @@ -var request = require('request'); - +var request = require('request') +var base_url = "http://localhost:3000/movies" describe("Endpoints under /movies", function() { - + it('responds with a 200 status code', function (done){ + request.get(base_url, function(error, response, body){ + expect(response.statusCode).toEqual(200) + done() + }) + }) + + describe("the returned json data", function() { + it('is an array', function(done) { + request.get(base_url, function(error, response, body) { + var movies = JSON.parse(body)[0] + expect(typeof movies).toEqual('object') + done() + }) + }) + + it('has the right values for the keys', function(done) { + request.get(base_url, function(error, response, body) { + var movies = JSON.parse(body)[0]['id'] + expect(movies.title).toEqual("Psycho") + done() + }) + }) + + it('has the right values for the keys', function(done) { + request.get(base_url, function(error, response, body) { + var movies = JSON.parse(body)[0]['id'] + expect(movies.overview).toEqual("When larcenous real estate clerk Marion Crane goes on the lam with a wad of cash and hopes of starting a new life, she ends up at the notorious Bates Motel, where manager Norman Bates cares for his housebound mother. The place seems quirky, but fine… until Marion decides to take a shower.") + done() + }) + }) + + + + }) + + + + + }) From cabff1192c81f906adcf5c66b6932591454bc247 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 24 Jun 2016 09:10:26 -0700 Subject: [PATCH 34/46] working on test --- .../lcov-report/VideoStoreAPI/app.js.html | 257 ++++++++++++++++ .../controllers/customers_controller.js.html | 230 ++++++++++++++ .../VideoStoreAPI/controllers/index.html | 119 ++++++++ .../controllers/movies_controller.js.html | 230 ++++++++++++++ .../controllers/rentals_controller.js.html | 191 ++++++++++++ coverage/lcov-report/VideoStoreAPI/index.html | 93 ++++++ .../VideoStoreAPI/models/customer.js.html | 260 ++++++++++++++++ .../VideoStoreAPI/models/index.html | 119 ++++++++ .../VideoStoreAPI/models/movie.js.html | 191 ++++++++++++ .../VideoStoreAPI/models/rental.js.html | 275 +++++++++++++++++ .../VideoStoreAPI/routes/index.html | 106 +++++++ .../VideoStoreAPI/routes/index.js.html | 284 ++++++++++++++++++ .../VideoStoreAPI/routes/zomg.js.html | 167 ++++++++++ coverage/lcov-report/base.css | 213 +++++++++++++ coverage/lcov-report/index.html | 132 ++++++++ coverage/lcov-report/prettify.css | 1 + coverage/lcov-report/prettify.js | 1 + coverage/lcov-report/sort-arrow-sprite.png | Bin 0 -> 209 bytes coverage/lcov-report/sorter.js | 158 ++++++++++ 19 files changed, 3027 insertions(+) create mode 100644 coverage/lcov-report/VideoStoreAPI/app.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/customer.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/movie.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/models/rental.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/index.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/index.js.html create mode 100644 coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html create mode 100644 coverage/lcov-report/base.css create mode 100644 coverage/lcov-report/index.html create mode 100644 coverage/lcov-report/prettify.css create mode 100644 coverage/lcov-report/prettify.js create mode 100644 coverage/lcov-report/sort-arrow-sprite.png create mode 100644 coverage/lcov-report/sorter.js diff --git a/coverage/lcov-report/VideoStoreAPI/app.js.html b/coverage/lcov-report/VideoStoreAPI/app.js.html new file mode 100644 index 000000000..781994810 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/app.js.html @@ -0,0 +1,257 @@ + + + + Code coverage report for VideoStoreAPI/app.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/ app.js +

+
+
+ 75.76% + Statements + 25/33 +
+
+ 16.67% + Branches + 1/6 +
+
+ 0% + Functions + 0/3 +
+
+ 75.76% + Lines + 25/33 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 + + + + + +  + + +  + +  + + +  +  + + +  + +  + +  +  +  + + + + + +  + + +  +  + +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  + 
var express = require('express')
+var path = require('path')
+var favicon = require('serve-favicon')
+var logger = require('morgan')
+var cookieParser = require('cookie-parser')
+var bodyParser = require('body-parser')
+ 
+var massive = require('massive')
+var connectionString = "postgres://localhost/video-store-api"
+ 
+var app = module.exports = express()
+ 
+var db = massive.connectSync({connectionString : connectionString})
+app.set('db', db)
+ 
+// view engine setup
+app.set('views', path.join(__dirname, 'views'))
+app.set('view engine', 'jade')
+ 
+var routes = require('./routes/index')
+ 
+var zomgRoutes = require('./routes/zomg')
+ 
+// uncomment after placing your favicon in /public
+//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')))
+app.use(logger('dev'))
+app.use(bodyParser.json())
+app.use(bodyParser.urlencoded({ extended: false }))
+app.use(cookieParser())
+app.use(express.static(path.join(__dirname, 'public')))
+ 
+app.use('/', routes)
+app.use('/zomg', zomgRoutes)
+ 
+// catch 404 and forward to error handler
+app.use(function(req, res, next) {
+  var err = new Error('Not Found')
+  err.status = 404
+  next(err)
+})
+ 
+// error handlers
+ 
+// development error handler
+// will print stacktrace
+Iif (app.get('env') === 'development') {
+  app.use(function(err, req, res, next) {
+    res.status(err.status || 500)
+    res.render('error', {
+      message: err.message,
+      error: err
+    })
+  })
+}
+ 
+// production error handler
+// no stacktraces leaked to user
+app.use(function(err, req, res, next) {
+  res.status(err.status || 500)
+  res.render('error', {
+    message: err.message,
+    error: {}
+  })
+})
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html new file mode 100644 index 000000000..f9189beec --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html @@ -0,0 +1,230 @@ + + + + Code coverage report for VideoStoreAPI/controllers/customers_controller.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ customers_controller.js +

+
+
+ 14.29% + Statements + 4/28 +
+
+ 0% + Branches + 0/8 +
+
+ 0% + Functions + 0/8 +
+
+ 14.29% + Lines + 4/28 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var Customer = require("../models/customer")
+var Rental = require("../models/rental")
+ 
+var CustomersController = {
+ 
+  index: function(req, res, next) {
+    Customer.all(function(error, customers) {
+      if(error) {
+        var err = new Error("Error retrieving customers:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(customers)
+      }
+    })
+  },
+ 
+  sort: function(req, res, next) {
+    Customer.sort(req.params.column_name, req.params.columns, req.query.n, req.query.p, function(error, customers) {
+      if(error) {
+        var err = new Error("Error retrieving customers:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(customers)
+      }
+    })
+  },
+ 
+  current: function(req, res, next) {
+    Rental.current_id(req.params.id, req.params.column_name, function(error, rentals) {
+      if(error) {
+        var err = new Error("Error retrieving rentals" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(rentals)
+      }
+    })
+  },
+ 
+  history: function(req, res, next) {
+    Rental.history_cust_id(req.params.id, req.params.column_name, req.params.column, function(error, rentals) {
+      if(error) {
+        var err = new Error("Error retrieving rentals:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(rentals)
+      }
+    })
+  }
+}
+ 
+module.exports = CustomersController
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/index.html b/coverage/lcov-report/VideoStoreAPI/controllers/index.html new file mode 100644 index 000000000..240267f9a --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/index.html @@ -0,0 +1,119 @@ + + + + Code coverage report for VideoStoreAPI/controllers/ + + + + + + + +
+
+

+ all files VideoStoreAPI/controllers/ +

+
+
+ 19.4% + Statements + 13/67 +
+
+ 0% + Branches + 0/18 +
+
+ 0% + Functions + 0/18 +
+
+ 19.4% + Lines + 13/67 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
customers_controller.js
14.29%4/280%0/80%0/814.29%4/28
movies_controller.js
14.29%4/280%0/80%0/814.29%4/28
rentals_controller.js
45.45%5/110%0/20%0/245.45%5/11
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html new file mode 100644 index 000000000..596468122 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html @@ -0,0 +1,230 @@ + + + + Code coverage report for VideoStoreAPI/controllers/movies_controller.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ movies_controller.js +

+
+
+ 14.29% + Statements + 4/28 +
+
+ 0% + Branches + 0/8 +
+
+ 0% + Functions + 0/8 +
+
+ 14.29% + Lines + 4/28 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var Movie = require("../models/movie")
+var Rental = require("../models/rental")
+ 
+var MoviesController = {
+ 
+  index: function(req, res, next) {
+    Movie.all(function(error, movies) {
+      if(error) {
+        var err = new Error("Error retrieving movies:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(movies)
+      }
+    })
+  },
+ 
+  sort: function(req, res, next) {
+    Movie.sort(req.params.column_name, req.query.n, req.query.p, function(error, movies) {
+      if(error) {
+        var err = new Error("Error retrieving movies:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(movies)
+      }
+    })
+  },
+ 
+  current: function(req, res, next) {
+    Rental.current_title(req.params.title, req.params.columns, function(error, rentals) {
+      if(error) {
+        var err = new Error("Error retrieving rentals:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(rentals)
+      }
+    })
+  },
+ 
+  history: function(req, res, next) {
+    Rental.history_title(req.params.title, req.params.column_name, function(error, rentals) {
+      if(error) {
+        var err = new Error("Error retrieving rentals:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        res.json(rentals)
+      }
+    })
+  }
+}
+ 
+module.exports = MoviesController
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html new file mode 100644 index 000000000..e9aacb9f3 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html @@ -0,0 +1,191 @@ + + + + Code coverage report for VideoStoreAPI/controllers/rentals_controller.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/controllers/ rentals_controller.js +

+
+
+ 45.45% + Statements + 5/11 +
+
+ 0% + Branches + 0/2 +
+
+ 0% + Functions + 0/2 +
+
+ 45.45% + Lines + 5/11 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 + + +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var Rental = require("../models/rental")
+var Movie = require("../models/movie")
+var Customer = require("../models/customer")
+ 
+var RentalsController = {
+  view: function(req, res, next) {
+    Rental.view(req.params.title, function(error, movies) {
+      if(error) {
+        var err = new Error("Error retrieving movies:\n" + error.message)
+        err.status = 500
+        next(err)
+      } else {
+        // console.log(res.json(movies))
+        res.json(movies)
+      }
+    })
+  }
+ 
+//   getRentals: function(req, res) {
+// 		Movie.findMovie(req.params.title, function(error, movie) {
+// 			if(error) {
+// 				var err = new Error("No such movie");
+// 				err.status = 404;
+// 			} else {
+// 				Rental.getCurrentlyCheckedOut(movie, function(error, checked_out) {
+// 					var return_data = {
+// 						title:movie.title,
+// 						overview:movie.overview,
+// 						release_date:movie.release_date,
+// 						total_inventory:movie.inventory,
+// 						available_copies:(parseInt(movie.inventory))-(parseInt(checked_out))
+// 					}
+// 					res.json(return_data)
+// 				})
+// 			}
+// ​
+// 		})
+// 	},
+ 
+}
+ 
+module.exports = RentalsController
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/index.html b/coverage/lcov-report/VideoStoreAPI/index.html new file mode 100644 index 000000000..62f39c3b9 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/index.html @@ -0,0 +1,93 @@ + + + + Code coverage report for VideoStoreAPI/ + + + + + + + +
+
+

+ all files VideoStoreAPI/ +

+
+
+ 75.76% + Statements + 25/33 +
+
+ 16.67% + Branches + 1/6 +
+
+ 0% + Functions + 0/3 +
+
+ 75.76% + Lines + 25/33 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
app.js
75.76%25/3316.67%1/60%0/375.76%25/33
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/customer.js.html b/coverage/lcov-report/VideoStoreAPI/models/customer.js.html new file mode 100644 index 000000000..4655368b2 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/customer.js.html @@ -0,0 +1,260 @@ + + + + Code coverage report for VideoStoreAPI/models/customer.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/models/ customer.js +

+
+
+ 50% + Statements + 13/26 +
+
+ 12.5% + Branches + 2/16 +
+
+ 44.44% + Functions + 4/9 +
+
+ 50% + Lines + 13/26 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 + +  + +400× +  +  + + + +  + +  +  + +400× +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var app = require("../app")
+var db = app.get('db')
+ 
+var Customer = function(id) {
+  this.id = id
+}
+ 
+Customer.all = function(callback) {
+  db.customers.find(function(error, customers) {
+    Iif(error) {
+      callback(error || new Error("Could not retrieve customers"), undefined)
+    } else Iif(!customers) {
+      callback(error || new Error("No customers found"), undefined)
+    } else {
+      callback(null, customers.map(function(customer) {
+        return new Customer(customer)
+      }))
+    }
+  })
+}
+ 
+Customer.sort = function(column_name, columns, n, p, callback) {
+  var options = {
+    limit : n,
+    offset : p,
+    columns : ["name", "registered_at", "postal_code"],
+    order : column_name
+  }
+ 
+  db.customers.find({}, options, function(error, customers) {
+    if(error) {
+      callback(error || new Error("Could not retrieve customers"), undefined)
+    } else if(!customers) {
+      callback(error || new Error("No customers found"), undefined)
+    } else {
+      callback(null, customers.map(function(customer) {
+        // console.log(customer)
+        return new Customer(customer)
+      }))
+    }
+  })
+}
+ 
+Customer.find_id = function(customer_ids, column_name, columns) {
+  var options = {
+    order : column_name,
+    columns : ['name', 'phone', 'account_credit']
+  }
+ 
+  db.customers.find({}, options, function(error, customer) {
+    // if(error) {
+    //   callback(error || new Error("Could not retrieve customers"), undefined)
+    // } else if(!customers) {
+    //   callback(error || new Error("No customers found"), undefined)
+    // } else {
+    //   callback(null, customers.map(function(customer) {
+    // console.log(customer)
+        return new Customer(customer)
+      // }))
+    // }
+  })
+}
+ 
+ 
+module.exports = Customer
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/index.html b/coverage/lcov-report/VideoStoreAPI/models/index.html new file mode 100644 index 000000000..2d044f09c --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/index.html @@ -0,0 +1,119 @@ + + + + Code coverage report for VideoStoreAPI/models/ + + + + + + + +
+
+

+ all files VideoStoreAPI/models/ +

+
+
+ 35.71% + Statements + 30/84 +
+
+ 4.76% + Branches + 2/42 +
+
+ 14.81% + Functions + 4/27 +
+
+ 35.71% + Lines + 30/84 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
customer.js
50%13/2612.5%2/1644.44%4/950%13/26
movie.js
27.27%6/220%0/160%0/727.27%6/22
rental.js
30.56%11/360%0/100%0/1130.56%11/36
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/movie.js.html b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html new file mode 100644 index 000000000..e87543541 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html @@ -0,0 +1,191 @@ + + + + Code coverage report for VideoStoreAPI/models/movie.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/models/ movie.js +

+
+
+ 27.27% + Statements + 6/22 +
+
+ 0% + Branches + 0/16 +
+
+ 0% + Functions + 0/7 +
+
+ 27.27% + Lines + 6/22 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 + +  + +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + 
var app = require("../app")
+var db = app.get('db')
+ 
+var Movie = function(id) {
+  this.id = id
+}
+ 
+Movie.all = function(callback) {
+  db.movies.find(function(error, movies) {
+    if(error) {
+      callback(error || new Error("Could not retrieve movies"), undefined)
+    } else if(!movies) {
+      callback(error || new Error("No movies found"), undefined)
+    } else {
+      callback(null, movies.map(function(movie) {
+        return new Movie(movie)
+      }))
+    }
+  })
+}
+ 
+Movie.sort = function(column_name, n, p, callback) {
+  var options = {
+    order : column_name,
+    limit : n,
+    offset : p
+  }
+ 
+  db.movies.find({}, options, function(error, movies) {
+    if(error) {
+      callback(error || new Error("Could not retrieve movies"), undefined)
+    } else if(!movies) {
+      callback(error || new Error("No movies found"), undefined)
+    } else {
+      callback(null, movies.map(function(movie) {
+        return new Movie(movie)
+      }))
+    }
+  })
+}
+ 
+module.exports = Movie
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/rental.js.html b/coverage/lcov-report/VideoStoreAPI/models/rental.js.html new file mode 100644 index 000000000..4bfad9f77 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/rental.js.html @@ -0,0 +1,275 @@ + + + + Code coverage report for VideoStoreAPI/models/rental.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/models/ rental.js +

+
+
+ 30.56% + Statements + 11/36 +
+
+ 0% + Branches + 0/10 +
+
+ 0% + Functions + 0/11 +
+
+ 30.56% + Lines + 11/36 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 + + + +  + +  +  +  + +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + +  +  +  +  +  +  +  +  +  +  + + 
var app = require("../app")
+var Customer = require("../models/customer")
+var Movie = require("../models/movie")
+var db = app.get('db')
+// Constructor function
+var Rental = function(id) {
+  this.id = id
+}
+ 
+Rental.view = function(title, callback) {
+  db.run("SELECT overview, release_date FROM movies WHERE title IN (SELECT title FROM rentals where title = $1 AND returned_date IS null)", [title], function(error, rentals) {
+    // console.log("rentals: " + JSON.stringify(rentals))
+    // console.log("error: " + error)
+    if(error) {
+      callback(error, undefined)
+    } else {
+      callback(null, rentals)
+    }
+  })
+}
+ 
+Rental.current_title = function(title, columns, callback) {
+  var options = {
+    columns : ['name', 'phone', 'account_credit']
+  }
+  db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers) {
+    if(error) {
+      callback(error, undefined)
+    } else {
+      callback(null, customers)
+    }
+  })
+}
+ 
+Rental.current_id = function(id, column_name, callback) {
+  var options = {
+    order : column_name
+  }
+  db.run("SELECT title FROM movies WHERE title IN (SELECT title FROM rentals WHERE customer_id::int = $1 AND returned_date IS null)", [id], function(error, movies) {
+    if(error) {
+      callback(error, undefined)
+    } else {
+      callback(null, movies)
+    }
+  })
+}
+ 
+Rental.history_title = function(title, column_name, callback) {
+  db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS NOT null)", [title], function(error, customer_ids) {
+    if(error) {
+      callback(error, undefined)
+    } else {
+      Customer.find_id(customer_ids, column_name)
+      callback(null, customer_ids)
+    }
+  })
+}
+ 
+Rental.history_cust_id = function(id, column_name, columns, callback) {
+  db.run("SELECT title FROM rentals WHERE customer_id = $1 AND returned_date IS NOT null", [id], function(error, customer_ids) {
+    if(error) {
+      callback(error, undefined)
+    } else {
+      Customer.find_id(customer_ids, column_name)
+      callback(null, customer_ids)
+    }
+  })
+}
+ 
+module.exports = Rental
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/index.html b/coverage/lcov-report/VideoStoreAPI/routes/index.html new file mode 100644 index 000000000..4d742a053 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/index.html @@ -0,0 +1,106 @@ + + + + Code coverage report for VideoStoreAPI/routes/ + + + + + + + +
+
+

+ all files VideoStoreAPI/routes/ +

+
+
+ 62.5% + Statements + 25/40 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/15 +
+
+ 62.5% + Lines + 25/40 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
index.js
58.82%20/34100%0/00%0/1458.82%20/34
zomg.js
83.33%5/6100%0/00%0/183.33%5/6
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/index.js.html b/coverage/lcov-report/VideoStoreAPI/routes/index.js.html new file mode 100644 index 000000000..3a6544cd0 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/index.js.html @@ -0,0 +1,284 @@ + + + + Code coverage report for VideoStoreAPI/routes/index.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/routes/ index.js +

+
+
+ 58.82% + Statements + 20/34 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/14 +
+
+ 58.82% + Lines + 20/34 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 + + + + +  + +  +  +  + +  +  +  + +  +  +  + +  +  +  +  + +  +  +  + +  +  +  + +  +  +  + +  +  +  + +  +  +  +  +  + +  +  +  +  + +  +  +  +  + +  +  +  +  + +  +  +  +  + +  +  +  +  +  +  + + 
var express = require('express')
+var router = express.Router()
+var movies_controller = require('../controllers/movies_controller')
+var customers_controller = require('../controllers/customers_controller')
+var rentals_controller = require('../controllers/rentals_controller')
+ 
+router.get('/', function(req, res, next) {
+  res.status(200).json({whatevs: 'whatevs!!!'})
+})
+ 
+router.get('/movies', function(req, res, next) {
+  movies_controller.index(req, res, next)
+})
+ 
+router.get('/movies/sort/:column_name', function(req, res, next) {
+  movies_controller.sort(req, res, next)
+})
+ 
+router.get('/movies/:title/current',
+function(req, res, next) {
+  movies_controller.current(req, res, next)
+})
+ 
+router.get('/movies/:title/history/sort/:column_name',function(req, res, next){
+  movies_controller.history(req, res, next)
+})
+ 
+router.get('/customers', function(req, res, next){
+  customers_controller.index(req, res, next)
+})
+ 
+router.get('/customers/sort/:column_name', function(req, res, next) {
+  customers_controller.sort(req, res, next)
+})
+ 
+router.get('/customers/:id/current', function(req, res, next){
+  customers_controller.current(req, res, next)
+})
+ 
+router.get('/customers/:id/history',
+function(req, res, next) {
+  customers_controller.history(req, res, next)
+})
+ 
+//TO DO
+router.get('/rentals/:title',
+function(req, res, next) {
+  rentals_controller.view(req, res, next)
+})
+ 
+router.get('/rentals/:title/customers',
+function(req, res, next) {
+  rentals_controller.customers(req, res, next)
+})
+ 
+router.get('/rentals/:title/check-out/:id',
+function(req, res, next) {
+  rentals_controller.check-out(req, res, next)
+})
+ 
+router.get('/rentals/:title/return/:id',
+function(req, res, next) {
+  rentals_controller.return(req, res, next)
+})
+ 
+router.get('/rentals/overdue',
+function(req, res, next) {
+  rentals_controller.overdue(req, res, next)
+})
+ 
+ 
+ 
+module.exports = router
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html b/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html new file mode 100644 index 000000000..5873d2d55 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html @@ -0,0 +1,167 @@ + + + + Code coverage report for VideoStoreAPI/routes/zomg.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/routes/ zomg.js +

+
+
+ 83.33% + Statements + 5/6 +
+
+ 100% + Branches + 0/0 +
+
+ 0% + Functions + 0/1 +
+
+ 83.33% + Lines + 5/6 +
+
+
+
+

+
+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  + + + +  +  + +  +  +  + + 
// Needed API endpoints w/HTTP verbs
+//
+// GET (/customers)
+//
+// GET (/customers/sort/name?n=10&p=2)
+//   name (n)
+//   registered_at (r)
+//   postal_code (p)
+// GET (/customers/:id/current)
+// GET (/customers/:id/history)
+//
+// GET (/movies)
+// GET (/movies/sort/release-date?n=5&p=1)
+//   title
+//   release_date
+// GET (/movies/:title/current)
+// GET (/movies/:title/history/sort/name)
+//
+// GET (/rentals/:title)
+// GET (/rentals/:title/customers)
+// UPDATE (/rentals/:id/:title/check-out)
+// UPDATE (/rentals/:id/:title/return)
+// GET (/rentals/overdue)
+ 
+var express = require('express');
+var router = express.Router();
+var locals = {}
+ 
+/* GET home page. */
+router.get('/', function(req, res, next) {
+  res.status(200).json({whatevs: 'zomg!!!'})
+});
+ 
+module.exports = router;
+ 
+
+
+ + + + + + + diff --git a/coverage/lcov-report/base.css b/coverage/lcov-report/base.css new file mode 100644 index 000000000..29737bcb0 --- /dev/null +++ b/coverage/lcov-report/base.css @@ -0,0 +1,213 @@ +body, html { + margin:0; padding: 0; + height: 100%; +} +body { + font-family: Helvetica Neue, Helvetica, Arial; + font-size: 14px; + color:#333; +} +.small { font-size: 12px; } +*, *:after, *:before { + -webkit-box-sizing:border-box; + -moz-box-sizing:border-box; + box-sizing:border-box; + } +h1 { font-size: 20px; margin: 0;} +h2 { font-size: 14px; } +pre { + font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; + margin: 0; + padding: 0; + -moz-tab-size: 2; + -o-tab-size: 2; + tab-size: 2; +} +a { color:#0074D9; text-decoration:none; } +a:hover { text-decoration:underline; } +.strong { font-weight: bold; } +.space-top1 { padding: 10px 0 0 0; } +.pad2y { padding: 20px 0; } +.pad1y { padding: 10px 0; } +.pad2x { padding: 0 20px; } +.pad2 { padding: 20px; } +.pad1 { padding: 10px; } +.space-left2 { padding-left:55px; } +.space-right2 { padding-right:20px; } +.center { text-align:center; } +.clearfix { display:block; } +.clearfix:after { + content:''; + display:block; + height:0; + clear:both; + visibility:hidden; + } +.fl { float: left; } +@media only screen and (max-width:640px) { + .col3 { width:100%; max-width:100%; } + .hide-mobile { display:none!important; } +} + +.quiet { + color: #7f7f7f; + color: rgba(0,0,0,0.5); +} +.quiet a { opacity: 0.7; } + +.fraction { + font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; + font-size: 10px; + color: #555; + background: #E8E8E8; + padding: 4px 5px; + border-radius: 3px; + vertical-align: middle; +} + +div.path a:link, div.path a:visited { color: #333; } +table.coverage { + border-collapse: collapse; + margin: 10px 0 0 0; + padding: 0; +} + +table.coverage td { + margin: 0; + padding: 0; + vertical-align: top; +} +table.coverage td.line-count { + text-align: right; + padding: 0 5px 0 20px; +} +table.coverage td.line-coverage { + text-align: right; + padding-right: 10px; + min-width:20px; +} + +table.coverage td span.cline-any { + display: inline-block; + padding: 0 5px; + width: 100%; +} +.missing-if-branch { + display: inline-block; + margin-right: 5px; + border-radius: 3px; + position: relative; + padding: 0 4px; + background: #333; + color: yellow; +} + +.skip-if-branch { + display: none; + margin-right: 10px; + position: relative; + padding: 0 4px; + background: #ccc; + color: white; +} +.missing-if-branch .typ, .skip-if-branch .typ { + color: inherit !important; +} +.coverage-summary { + border-collapse: collapse; + width: 100%; +} +.coverage-summary tr { border-bottom: 1px solid #bbb; } +.keyline-all { border: 1px solid #ddd; } +.coverage-summary td, .coverage-summary th { padding: 10px; } +.coverage-summary tbody { border: 1px solid #bbb; } +.coverage-summary td { border-right: 1px solid #bbb; } +.coverage-summary td:last-child { border-right: none; } +.coverage-summary th { + text-align: left; + font-weight: normal; + white-space: nowrap; +} +.coverage-summary th.file { border-right: none !important; } +.coverage-summary th.pct { } +.coverage-summary th.pic, +.coverage-summary th.abs, +.coverage-summary td.pct, +.coverage-summary td.abs { text-align: right; } +.coverage-summary td.file { white-space: nowrap; } +.coverage-summary td.pic { min-width: 120px !important; } +.coverage-summary tfoot td { } + +.coverage-summary .sorter { + height: 10px; + width: 7px; + display: inline-block; + margin-left: 0.5em; + background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; +} +.coverage-summary .sorted .sorter { + background-position: 0 -20px; +} +.coverage-summary .sorted-desc .sorter { + background-position: 0 -10px; +} +.status-line { height: 10px; } +/* dark red */ +.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } +.low .chart { border:1px solid #C21F39 } +/* medium red */ +.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } +/* light red */ +.low, .cline-no { background:#FCE1E5 } +/* light green */ +.high, .cline-yes { background:rgb(230,245,208) } +/* medium green */ +.cstat-yes { background:rgb(161,215,106) } +/* dark green */ +.status-line.high, .high .cover-fill { background:rgb(77,146,33) } +.high .chart { border:1px solid rgb(77,146,33) } +/* dark yellow (gold) */ +.medium .chart { border:1px solid #f9cd0b; } +.status-line.medium, .medium .cover-fill { background: #f9cd0b; } +/* light yellow */ +.medium { background: #fff4c2; } +/* light gray */ +span.cline-neutral { background: #eaeaea; } + +.cbranch-no { background: yellow !important; color: #111; } + +.cstat-skip { background: #ddd; color: #111; } +.fstat-skip { background: #ddd; color: #111 !important; } +.cbranch-skip { background: #ddd !important; color: #111; } + + +.cover-fill, .cover-empty { + display:inline-block; + height: 12px; +} +.chart { + line-height: 0; +} +.cover-empty { + background: white; +} +.cover-full { + border-right: none !important; +} +pre.prettyprint { + border: none !important; + padding: 0 !important; + margin: 0 !important; +} +.com { color: #999 !important; } +.ignore-none { color: #999; font-weight: normal; } + +.wrapper { + min-height: 100%; + height: auto !important; + height: 100%; + margin: 0 auto -48px; +} +.footer, .push { + height: 48px; +} diff --git a/coverage/lcov-report/index.html b/coverage/lcov-report/index.html new file mode 100644 index 000000000..58de4f051 --- /dev/null +++ b/coverage/lcov-report/index.html @@ -0,0 +1,132 @@ + + + + Code coverage report for All files + + + + + + + +
+
+

+ / +

+
+
+ 41.52% + Statements + 93/224 +
+
+ 4.55% + Branches + 3/66 +
+
+ 6.35% + Functions + 4/63 +
+
+ 41.52% + Lines + 93/224 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
VideoStoreAPI/
75.76%25/3316.67%1/60%0/375.76%25/33
VideoStoreAPI/controllers/
19.4%13/670%0/180%0/1819.4%13/67
VideoStoreAPI/models/
35.71%30/844.76%2/4214.81%4/2735.71%30/84
VideoStoreAPI/routes/
62.5%25/40100%0/00%0/1562.5%25/40
+
+
+ + + + + + + diff --git a/coverage/lcov-report/prettify.css b/coverage/lcov-report/prettify.css new file mode 100644 index 000000000..b317a7cda --- /dev/null +++ b/coverage/lcov-report/prettify.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/coverage/lcov-report/prettify.js b/coverage/lcov-report/prettify.js new file mode 100644 index 000000000..ef51e0386 --- /dev/null +++ b/coverage/lcov-report/prettify.js @@ -0,0 +1 @@ +window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/coverage/lcov-report/sort-arrow-sprite.png b/coverage/lcov-report/sort-arrow-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..03f704a609c6fd0dbfdac63466a7d7c958b5cbf3 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jii$m5978H@?Fn+^JD|Y9yzj{W`447Gxa{7*dM7nnnD-Lb z6^}Hx2)'; + } + } + return cols; + } + // attaches a data attribute to every tr element with an object + // of data values keyed by column name + function loadRowData(tableRow) { + var tableCols = tableRow.querySelectorAll('td'), + colNode, + col, + data = {}, + i, + val; + for (i = 0; i < tableCols.length; i += 1) { + colNode = tableCols[i]; + col = cols[i]; + val = colNode.getAttribute('data-value'); + if (col.type === 'number') { + val = Number(val); + } + data[col.key] = val; + } + return data; + } + // loads all row data + function loadData() { + var rows = getTableBody().querySelectorAll('tr'), + i; + + for (i = 0; i < rows.length; i += 1) { + rows[i].data = loadRowData(rows[i]); + } + } + // sorts the table using the data for the ith column + function sortByIndex(index, desc) { + var key = cols[index].key, + sorter = function (a, b) { + a = a.data[key]; + b = b.data[key]; + return a < b ? -1 : a > b ? 1 : 0; + }, + finalSorter = sorter, + tableBody = document.querySelector('.coverage-summary tbody'), + rowNodes = tableBody.querySelectorAll('tr'), + rows = [], + i; + + if (desc) { + finalSorter = function (a, b) { + return -1 * sorter(a, b); + }; + } + + for (i = 0; i < rowNodes.length; i += 1) { + rows.push(rowNodes[i]); + tableBody.removeChild(rowNodes[i]); + } + + rows.sort(finalSorter); + + for (i = 0; i < rows.length; i += 1) { + tableBody.appendChild(rows[i]); + } + } + // removes sort indicators for current column being sorted + function removeSortIndicators() { + var col = getNthColumn(currentSort.index), + cls = col.className; + + cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); + col.className = cls; + } + // adds sort indicators for current column being sorted + function addSortIndicators() { + getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; + } + // adds event listeners for all sorter widgets + function enableUI() { + var i, + el, + ithSorter = function ithSorter(i) { + var col = cols[i]; + + return function () { + var desc = col.defaultDescSort; + + if (currentSort.index === i) { + desc = !currentSort.desc; + } + sortByIndex(i, desc); + removeSortIndicators(); + currentSort.index = i; + currentSort.desc = desc; + addSortIndicators(); + }; + }; + for (i =0 ; i < cols.length; i += 1) { + if (cols[i].sortable) { + // add the click event handler on the th so users + // dont have to click on those tiny arrows + el = getNthColumn(i).querySelector('.sorter').parentElement; + if (el.addEventListener) { + el.addEventListener('click', ithSorter(i)); + } else { + el.attachEvent('onclick', ithSorter(i)); + } + } + } + } + // adds sorting functionality to the UI + return function () { + if (!getTable()) { + return; + } + cols = loadColumns(); + loadData(cols); + addSortIndicators(); + enableUI(); + }; +})(); + +window.addEventListener('load', addSorting); From 77ba333ca7437bc5a925726ed5b964d0912b3314 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 09:14:16 -0700 Subject: [PATCH 35/46] trying to get rental checkout going --- controllers/rentals_controller.js | 45 ++++++++++++++++--------------- models/rental.js | 44 +++++++++++++++++++++++++++++- routes/index.js | 2 +- 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js index 2afd76055..d9ce7b055 100644 --- a/controllers/rentals_controller.js +++ b/controllers/rentals_controller.js @@ -10,33 +10,34 @@ var RentalsController = { err.status = 500 next(err) } else { - // console.log(res.json(movies)) res.json(movies) } }) - } + }, -// getRentals: function(req, res) { -// Movie.findMovie(req.params.title, function(error, movie) { -// if(error) { -// var err = new Error("No such movie"); -// err.status = 404; -// } else { -// Rental.getCurrentlyCheckedOut(movie, function(error, checked_out) { -// var return_data = { -// title:movie.title, -// overview:movie.overview, -// release_date:movie.release_date, -// total_inventory:movie.inventory, -// available_copies:(parseInt(movie.inventory))-(parseInt(checked_out)) -// } -// res.json(return_data) -// }) -// } -// ​ -// }) -// }, + customers: function(req, res, next) { + Rental.customers(req.params.title, function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + }, + check_out: function(req, res, next) { + Rental.check_out(req.params.title, req.params.customer_id, function(error, check_out) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(check_out) + } + }) + } } module.exports = RentalsController diff --git a/models/rental.js b/models/rental.js index 9dc7c5189..2fa47bb03 100644 --- a/models/rental.js +++ b/models/rental.js @@ -8,7 +8,7 @@ var Rental = function(id) { } Rental.view = function(title, callback) { - db.run("SELECT overview, release_date FROM movies WHERE title IN (SELECT title FROM rentals where title = $1 AND returned_date IS null)", [title], function(error, rentals) { + db.run("SELECT overview, release_date FROM movies WHERE title IN (SELECT title FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, rentals) { // console.log("rentals: " + JSON.stringify(rentals)) // console.log("error: " + error) if(error) { @@ -19,6 +19,48 @@ Rental.view = function(title, callback) { }) } +Rental.customers = function(title, callback) { + db.run("SELECT name FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers) { + if(error) { + callback(error, undefined) + } else { + callback(null, customers) + } + }) +} + +Rental.check_out = function(title, customer_id, callback) { + var today = new Date() + var today_plus_two = new Date(today) + today_plus_two.setDate(today_plus_two.getDate() + 2) + + var movie_id = db.run("SELECT id FROM rentals WHERE title = $1 LIMIT 1", [title]) + + db.rentals.save({ + movie_id: movie_id, + customer_id: customer_id, + title: title, + checkout_date: today, + due_date: today_plus_two, + returned_date: null + } + // , function (error, rental) { + // if (error) { + // callback(error, undefined) + // } + // callback(null, rental) + // } +) + + db.run("UPDATE customers SET account_credit=account_credit-4 WHERE id=$1;", [customer_id], function (error, charged) { + if (error) { + callback(error, undefined); + } else { + callback(null, charged) + } + }) +} + Rental.current_title = function(title, columns, callback) { var options = { columns : ['name', 'phone', 'account_credit'] diff --git a/routes/index.js b/routes/index.js index beb681b0c..54cb8a76f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -55,7 +55,7 @@ function(req, res, next) { router.get('/rentals/:title/check-out/:id', function(req, res, next) { - rentals_controller.check-out(req, res, next) + rentals_controller.check_out(req, res, next) }) router.get('/rentals/:title/return/:id', From daf30f296f80a9e46d85808bd24dc69cc4ce4917 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 09:38:36 -0700 Subject: [PATCH 36/46] added routes, views for json and html doc pages) --- app.js | 4 ++++ routes/index.js | 8 ++++++++ views/docs.html | 6 ++++++ views/docs_json.html | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 views/docs.html create mode 100644 views/docs_json.html diff --git a/app.js b/app.js index 81057e3f6..80e5b00a7 100644 --- a/app.js +++ b/app.js @@ -17,6 +17,10 @@ app.set('db', db) app.set('views', path.join(__dirname, 'views')) app.set('view engine', 'jade') +//views...? +app.engine('html', require('ejs').renderFile) +app.set('view engine', 'html') + var routes = require('./routes/index') var zomgRoutes = require('./routes/zomg') diff --git a/routes/index.js b/routes/index.js index 54cb8a76f..1b7f5b3f1 100644 --- a/routes/index.js +++ b/routes/index.js @@ -68,6 +68,14 @@ function(req, res, next) { rentals_controller.overdue(req, res, next) }) +router.get('/api/docs', +function(req, res, next) { + res.render('docs', { title: 'API Docs - HTML'}) +}) +router.get('/api/docs.json', +function(req,res) { + res.render('docs_json') +}) module.exports = router diff --git a/views/docs.html b/views/docs.html new file mode 100644 index 000000000..3961cc152 --- /dev/null +++ b/views/docs.html @@ -0,0 +1,6 @@ + + + +

docs!

+ + diff --git a/views/docs_json.html b/views/docs_json.html new file mode 100644 index 000000000..b4a111ac7 --- /dev/null +++ b/views/docs_json.html @@ -0,0 +1,34 @@ + + + Express HTML + + + + + + +
+ +
+

Hello, world!

+

This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.

+

Learn more

+
+
+ + From ef917e9b121b8c6f1237baf1497dbee059486574 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 24 Jun 2016 09:42:26 -0700 Subject: [PATCH 37/46] working on tests for customers models --- coverage/coverage.json | 1 + .../lcov-report/VideoStoreAPI/app.js.html | 2 +- .../controllers/customers_controller.js.html | 2 +- .../VideoStoreAPI/controllers/index.html | 2 +- .../controllers/movies_controller.js.html | 2 +- .../controllers/rentals_controller.js.html | 2 +- coverage/lcov-report/VideoStoreAPI/index.html | 2 +- .../VideoStoreAPI/models/customer.js.html | 36 +- .../VideoStoreAPI/models/index.html | 36 +- .../VideoStoreAPI/models/movie.js.html | 2 +- .../VideoStoreAPI/models/rental.js.html | 2 +- .../VideoStoreAPI/routes/index.html | 2 +- .../VideoStoreAPI/routes/index.js.html | 2 +- .../VideoStoreAPI/routes/zomg.js.html | 2 +- coverage/lcov-report/index.html | 36 +- coverage/lcov.info | 497 ++++++++++++++++++ package.json | 4 +- spec/controllers/customers.spec.js | 104 +++- spec/models/customer.spec.js | 45 ++ 19 files changed, 693 insertions(+), 88 deletions(-) create mode 100644 coverage/coverage.json create mode 100644 coverage/lcov.info create mode 100644 spec/models/customer.spec.js diff --git a/coverage/coverage.json b/coverage/coverage.json new file mode 100644 index 000000000..5336593d0 --- /dev/null +++ b/coverage/coverage.json @@ -0,0 +1 @@ +{"/Users/sakne/C5/projects/VideoStoreAPI/app.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/app.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1,"18":1,"19":1,"20":1,"21":1,"22":1,"23":1,"24":0,"25":0,"26":0,"27":1,"28":0,"29":0,"30":0,"31":1,"32":0,"33":0},"b":{"1":[0,1],"2":[0,0],"3":[0,0]},"f":{"1":0,"2":0,"3":0},"fnMap":{"1":{"name":"(anonymous_1)","line":36,"loc":{"start":{"line":36,"column":8},"end":{"line":36,"column":33}}},"2":{"name":"(anonymous_2)","line":47,"loc":{"start":{"line":47,"column":10},"end":{"line":47,"column":40}}},"3":{"name":"(anonymous_3)","line":58,"loc":{"start":{"line":58,"column":8},"end":{"line":58,"column":38}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":26}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":38}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":30}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":43}},"6":{"start":{"line":6,"column":0},"end":{"line":6,"column":39}},"7":{"start":{"line":8,"column":0},"end":{"line":8,"column":32}},"8":{"start":{"line":9,"column":0},"end":{"line":9,"column":61}},"9":{"start":{"line":11,"column":0},"end":{"line":11,"column":36}},"10":{"start":{"line":13,"column":0},"end":{"line":13,"column":67}},"11":{"start":{"line":14,"column":0},"end":{"line":14,"column":17}},"12":{"start":{"line":17,"column":0},"end":{"line":17,"column":47}},"13":{"start":{"line":18,"column":0},"end":{"line":18,"column":30}},"14":{"start":{"line":20,"column":0},"end":{"line":20,"column":38}},"15":{"start":{"line":22,"column":0},"end":{"line":22,"column":41}},"16":{"start":{"line":26,"column":0},"end":{"line":26,"column":22}},"17":{"start":{"line":27,"column":0},"end":{"line":27,"column":26}},"18":{"start":{"line":28,"column":0},"end":{"line":28,"column":51}},"19":{"start":{"line":29,"column":0},"end":{"line":29,"column":23}},"20":{"start":{"line":30,"column":0},"end":{"line":30,"column":55}},"21":{"start":{"line":32,"column":0},"end":{"line":32,"column":20}},"22":{"start":{"line":33,"column":0},"end":{"line":33,"column":28}},"23":{"start":{"line":36,"column":0},"end":{"line":40,"column":2}},"24":{"start":{"line":37,"column":2},"end":{"line":37,"column":34}},"25":{"start":{"line":38,"column":2},"end":{"line":38,"column":18}},"26":{"start":{"line":39,"column":2},"end":{"line":39,"column":11}},"27":{"start":{"line":46,"column":0},"end":{"line":54,"column":1}},"28":{"start":{"line":47,"column":2},"end":{"line":53,"column":4}},"29":{"start":{"line":48,"column":4},"end":{"line":48,"column":33}},"30":{"start":{"line":49,"column":4},"end":{"line":52,"column":6}},"31":{"start":{"line":58,"column":0},"end":{"line":64,"column":2}},"32":{"start":{"line":59,"column":2},"end":{"line":59,"column":31}},"33":{"start":{"line":60,"column":2},"end":{"line":63,"column":4}}},"branchMap":{"1":{"line":46,"type":"if","locations":[{"start":{"line":46,"column":0},"end":{"line":46,"column":0}},{"start":{"line":46,"column":0},"end":{"line":46,"column":0}}]},"2":{"line":48,"type":"binary-expr","locations":[{"start":{"line":48,"column":15},"end":{"line":48,"column":25}},{"start":{"line":48,"column":29},"end":{"line":48,"column":32}}]},"3":{"line":59,"type":"binary-expr","locations":[{"start":{"line":59,"column":13},"end":{"line":59,"column":23}},{"start":{"line":59,"column":27},"end":{"line":59,"column":30}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/routes/index.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/routes/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":0,"8":1,"9":0,"10":1,"11":0,"12":1,"13":0,"14":1,"15":0,"16":1,"17":0,"18":1,"19":0,"20":1,"21":0,"22":1,"23":0,"24":1,"25":0,"26":1,"27":0,"28":1,"29":0,"30":1,"31":0,"32":1,"33":0,"34":1},"b":{},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":7,"loc":{"start":{"line":7,"column":16},"end":{"line":7,"column":41}}},"2":{"name":"(anonymous_2)","line":11,"loc":{"start":{"line":11,"column":22},"end":{"line":11,"column":47}}},"3":{"name":"(anonymous_3)","line":15,"loc":{"start":{"line":15,"column":40},"end":{"line":15,"column":65}}},"4":{"name":"(anonymous_4)","line":20,"loc":{"start":{"line":20,"column":0},"end":{"line":20,"column":25}}},"5":{"name":"(anonymous_5)","line":24,"loc":{"start":{"line":24,"column":54},"end":{"line":24,"column":78}}},"6":{"name":"(anonymous_6)","line":28,"loc":{"start":{"line":28,"column":25},"end":{"line":28,"column":49}}},"7":{"name":"(anonymous_7)","line":32,"loc":{"start":{"line":32,"column":43},"end":{"line":32,"column":68}}},"8":{"name":"(anonymous_8)","line":36,"loc":{"start":{"line":36,"column":37},"end":{"line":36,"column":61}}},"9":{"name":"(anonymous_9)","line":41,"loc":{"start":{"line":41,"column":0},"end":{"line":41,"column":25}}},"10":{"name":"(anonymous_10)","line":47,"loc":{"start":{"line":47,"column":0},"end":{"line":47,"column":25}}},"11":{"name":"(anonymous_11)","line":52,"loc":{"start":{"line":52,"column":0},"end":{"line":52,"column":25}}},"12":{"name":"(anonymous_12)","line":57,"loc":{"start":{"line":57,"column":0},"end":{"line":57,"column":25}}},"13":{"name":"(anonymous_13)","line":62,"loc":{"start":{"line":62,"column":0},"end":{"line":62,"column":25}}},"14":{"name":"(anonymous_14)","line":67,"loc":{"start":{"line":67,"column":0},"end":{"line":67,"column":25}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":29}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":67}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":73}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":69}},"6":{"start":{"line":7,"column":0},"end":{"line":9,"column":2}},"7":{"start":{"line":8,"column":2},"end":{"line":8,"column":47}},"8":{"start":{"line":11,"column":0},"end":{"line":13,"column":2}},"9":{"start":{"line":12,"column":2},"end":{"line":12,"column":41}},"10":{"start":{"line":15,"column":0},"end":{"line":17,"column":2}},"11":{"start":{"line":16,"column":2},"end":{"line":16,"column":40}},"12":{"start":{"line":19,"column":0},"end":{"line":22,"column":2}},"13":{"start":{"line":21,"column":2},"end":{"line":21,"column":43}},"14":{"start":{"line":24,"column":0},"end":{"line":26,"column":2}},"15":{"start":{"line":25,"column":2},"end":{"line":25,"column":43}},"16":{"start":{"line":28,"column":0},"end":{"line":30,"column":2}},"17":{"start":{"line":29,"column":2},"end":{"line":29,"column":44}},"18":{"start":{"line":32,"column":0},"end":{"line":34,"column":2}},"19":{"start":{"line":33,"column":2},"end":{"line":33,"column":43}},"20":{"start":{"line":36,"column":0},"end":{"line":38,"column":2}},"21":{"start":{"line":37,"column":2},"end":{"line":37,"column":46}},"22":{"start":{"line":40,"column":0},"end":{"line":43,"column":2}},"23":{"start":{"line":42,"column":2},"end":{"line":42,"column":46}},"24":{"start":{"line":46,"column":0},"end":{"line":49,"column":2}},"25":{"start":{"line":48,"column":2},"end":{"line":48,"column":41}},"26":{"start":{"line":51,"column":0},"end":{"line":54,"column":2}},"27":{"start":{"line":53,"column":2},"end":{"line":53,"column":46}},"28":{"start":{"line":56,"column":0},"end":{"line":59,"column":2}},"29":{"start":{"line":58,"column":2},"end":{"line":58,"column":46}},"30":{"start":{"line":61,"column":0},"end":{"line":64,"column":2}},"31":{"start":{"line":63,"column":2},"end":{"line":63,"column":43}},"32":{"start":{"line":66,"column":0},"end":{"line":69,"column":2}},"33":{"start":{"line":68,"column":2},"end":{"line":68,"column":44}},"34":{"start":{"line":73,"column":0},"end":{"line":73,"column":23}}},"branchMap":{}},"/Users/sakne/C5/projects/VideoStoreAPI/controllers/movies_controller.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/controllers/movies_controller.js","s":{"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":34}}},"2":{"name":"(anonymous_2)","line":7,"loc":{"start":{"line":7,"column":14},"end":{"line":7,"column":38}}},"3":{"name":"(anonymous_3)","line":18,"loc":{"start":{"line":18,"column":8},"end":{"line":18,"column":33}}},"4":{"name":"(anonymous_4)","line":19,"loc":{"start":{"line":19,"column":65},"end":{"line":19,"column":89}}},"5":{"name":"(anonymous_5)","line":30,"loc":{"start":{"line":30,"column":11},"end":{"line":30,"column":36}}},"6":{"name":"(anonymous_6)","line":31,"loc":{"start":{"line":31,"column":63},"end":{"line":31,"column":88}}},"7":{"name":"(anonymous_7)","line":42,"loc":{"start":{"line":42,"column":11},"end":{"line":42,"column":36}}},"8":{"name":"(anonymous_8)","line":43,"loc":{"start":{"line":43,"column":67},"end":{"line":43,"column":92}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":40}},"3":{"start":{"line":4,"column":0},"end":{"line":53,"column":1}},"4":{"start":{"line":7,"column":4},"end":{"line":15,"column":6}},"5":{"start":{"line":8,"column":6},"end":{"line":14,"column":7}},"6":{"start":{"line":9,"column":8},"end":{"line":9,"column":73}},"7":{"start":{"line":10,"column":8},"end":{"line":10,"column":24}},"8":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"9":{"start":{"line":13,"column":8},"end":{"line":13,"column":24}},"10":{"start":{"line":19,"column":4},"end":{"line":27,"column":6}},"11":{"start":{"line":20,"column":6},"end":{"line":26,"column":7}},"12":{"start":{"line":21,"column":8},"end":{"line":21,"column":73}},"13":{"start":{"line":22,"column":8},"end":{"line":22,"column":24}},"14":{"start":{"line":23,"column":8},"end":{"line":23,"column":17}},"15":{"start":{"line":25,"column":8},"end":{"line":25,"column":24}},"16":{"start":{"line":31,"column":4},"end":{"line":39,"column":6}},"17":{"start":{"line":32,"column":6},"end":{"line":38,"column":7}},"18":{"start":{"line":33,"column":8},"end":{"line":33,"column":74}},"19":{"start":{"line":34,"column":8},"end":{"line":34,"column":24}},"20":{"start":{"line":35,"column":8},"end":{"line":35,"column":17}},"21":{"start":{"line":37,"column":8},"end":{"line":37,"column":25}},"22":{"start":{"line":43,"column":4},"end":{"line":51,"column":6}},"23":{"start":{"line":44,"column":6},"end":{"line":50,"column":7}},"24":{"start":{"line":45,"column":8},"end":{"line":45,"column":74}},"25":{"start":{"line":46,"column":8},"end":{"line":46,"column":24}},"26":{"start":{"line":47,"column":8},"end":{"line":47,"column":17}},"27":{"start":{"line":49,"column":8},"end":{"line":49,"column":25}},"28":{"start":{"line":55,"column":0},"end":{"line":55,"column":33}}},"branchMap":{"1":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":6},"end":{"line":8,"column":6}},{"start":{"line":8,"column":6},"end":{"line":8,"column":6}}]},"2":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":6},"end":{"line":20,"column":6}},{"start":{"line":20,"column":6},"end":{"line":20,"column":6}}]},"3":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":6},"end":{"line":32,"column":6}},{"start":{"line":32,"column":6},"end":{"line":32,"column":6}}]},"4":{"line":44,"type":"if","locations":[{"start":{"line":44,"column":6},"end":{"line":44,"column":6}},{"start":{"line":44,"column":6},"end":{"line":44,"column":6}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/models/movie.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/models/movie.js","s":{"1":1,"2":1,"3":1,"4":0,"5":1,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":1,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":25}}},"2":{"name":"(anonymous_2)","line":8,"loc":{"start":{"line":8,"column":12},"end":{"line":8,"column":31}}},"3":{"name":"(anonymous_3)","line":9,"loc":{"start":{"line":9,"column":17},"end":{"line":9,"column":41}}},"4":{"name":"(anonymous_4)","line":15,"loc":{"start":{"line":15,"column":32},"end":{"line":15,"column":48}}},"5":{"name":"(anonymous_5)","line":22,"loc":{"start":{"line":22,"column":13},"end":{"line":22,"column":51}}},"6":{"name":"(anonymous_6)","line":29,"loc":{"start":{"line":29,"column":30},"end":{"line":29,"column":54}}},"7":{"name":"(anonymous_7)","line":35,"loc":{"start":{"line":35,"column":32},"end":{"line":35,"column":48}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":22}},"3":{"start":{"line":4,"column":0},"end":{"line":6,"column":1}},"4":{"start":{"line":5,"column":2},"end":{"line":5,"column":14}},"5":{"start":{"line":8,"column":0},"end":{"line":20,"column":1}},"6":{"start":{"line":9,"column":2},"end":{"line":19,"column":4}},"7":{"start":{"line":10,"column":4},"end":{"line":18,"column":5}},"8":{"start":{"line":11,"column":6},"end":{"line":11,"column":74}},"9":{"start":{"line":12,"column":11},"end":{"line":18,"column":5}},"10":{"start":{"line":13,"column":6},"end":{"line":13,"column":64}},"11":{"start":{"line":15,"column":6},"end":{"line":17,"column":9}},"12":{"start":{"line":16,"column":8},"end":{"line":16,"column":31}},"13":{"start":{"line":22,"column":0},"end":{"line":40,"column":1}},"14":{"start":{"line":23,"column":2},"end":{"line":27,"column":3}},"15":{"start":{"line":29,"column":2},"end":{"line":39,"column":4}},"16":{"start":{"line":30,"column":4},"end":{"line":38,"column":5}},"17":{"start":{"line":31,"column":6},"end":{"line":31,"column":74}},"18":{"start":{"line":32,"column":11},"end":{"line":38,"column":5}},"19":{"start":{"line":33,"column":6},"end":{"line":33,"column":64}},"20":{"start":{"line":35,"column":6},"end":{"line":37,"column":9}},"21":{"start":{"line":36,"column":8},"end":{"line":36,"column":31}},"22":{"start":{"line":42,"column":0},"end":{"line":42,"column":22}}},"branchMap":{"1":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":4},"end":{"line":10,"column":4}},{"start":{"line":10,"column":4},"end":{"line":10,"column":4}}]},"2":{"line":11,"type":"binary-expr","locations":[{"start":{"line":11,"column":15},"end":{"line":11,"column":20}},{"start":{"line":11,"column":24},"end":{"line":11,"column":62}}]},"3":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":11},"end":{"line":12,"column":11}},{"start":{"line":12,"column":11},"end":{"line":12,"column":11}}]},"4":{"line":13,"type":"binary-expr","locations":[{"start":{"line":13,"column":15},"end":{"line":13,"column":20}},{"start":{"line":13,"column":24},"end":{"line":13,"column":52}}]},"5":{"line":30,"type":"if","locations":[{"start":{"line":30,"column":4},"end":{"line":30,"column":4}},{"start":{"line":30,"column":4},"end":{"line":30,"column":4}}]},"6":{"line":31,"type":"binary-expr","locations":[{"start":{"line":31,"column":15},"end":{"line":31,"column":20}},{"start":{"line":31,"column":24},"end":{"line":31,"column":62}}]},"7":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":11},"end":{"line":32,"column":11}},{"start":{"line":32,"column":11},"end":{"line":32,"column":11}}]},"8":{"line":33,"type":"binary-expr","locations":[{"start":{"line":33,"column":15},"end":{"line":33,"column":20}},{"start":{"line":33,"column":24},"end":{"line":33,"column":52}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/models/rental.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/models/rental.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":0,"7":1,"8":0,"9":0,"10":0,"11":0,"12":1,"13":0,"14":0,"15":0,"16":0,"17":0,"18":1,"19":0,"20":0,"21":0,"22":0,"23":0,"24":1,"25":0,"26":0,"27":0,"28":0,"29":0,"30":1,"31":0,"32":0,"33":0,"34":0,"35":0,"36":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":13},"end":{"line":6,"column":26}}},"2":{"name":"(anonymous_2)","line":10,"loc":{"start":{"line":10,"column":14},"end":{"line":10,"column":40}}},"3":{"name":"(anonymous_3)","line":11,"loc":{"start":{"line":11,"column":149},"end":{"line":11,"column":174}}},"4":{"name":"(anonymous_4)","line":22,"loc":{"start":{"line":22,"column":23},"end":{"line":22,"column":58}}},"5":{"name":"(anonymous_5)","line":26,"loc":{"start":{"line":26,"column":165},"end":{"line":26,"column":192}}},"6":{"name":"(anonymous_6)","line":35,"loc":{"start":{"line":35,"column":20},"end":{"line":35,"column":56}}},"7":{"name":"(anonymous_7)","line":39,"loc":{"start":{"line":39,"column":140},"end":{"line":39,"column":164}}},"8":{"name":"(anonymous_8)","line":48,"loc":{"start":{"line":48,"column":23},"end":{"line":48,"column":62}}},"9":{"name":"(anonymous_9)","line":49,"loc":{"start":{"line":49,"column":169},"end":{"line":49,"column":199}}},"10":{"name":"(anonymous_10)","line":59,"loc":{"start":{"line":59,"column":25},"end":{"line":59,"column":70}}},"11":{"name":"(anonymous_11)","line":60,"loc":{"start":{"line":60,"column":97},"end":{"line":60,"column":127}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":44}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":38}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":22}},"5":{"start":{"line":6,"column":0},"end":{"line":8,"column":1}},"6":{"start":{"line":7,"column":2},"end":{"line":7,"column":14}},"7":{"start":{"line":10,"column":0},"end":{"line":20,"column":1}},"8":{"start":{"line":11,"column":2},"end":{"line":19,"column":4}},"9":{"start":{"line":14,"column":4},"end":{"line":18,"column":5}},"10":{"start":{"line":15,"column":6},"end":{"line":15,"column":32}},"11":{"start":{"line":17,"column":6},"end":{"line":17,"column":29}},"12":{"start":{"line":22,"column":0},"end":{"line":33,"column":1}},"13":{"start":{"line":23,"column":2},"end":{"line":25,"column":3}},"14":{"start":{"line":26,"column":2},"end":{"line":32,"column":4}},"15":{"start":{"line":27,"column":4},"end":{"line":31,"column":5}},"16":{"start":{"line":28,"column":6},"end":{"line":28,"column":32}},"17":{"start":{"line":30,"column":6},"end":{"line":30,"column":31}},"18":{"start":{"line":35,"column":0},"end":{"line":46,"column":1}},"19":{"start":{"line":36,"column":2},"end":{"line":38,"column":3}},"20":{"start":{"line":39,"column":2},"end":{"line":45,"column":4}},"21":{"start":{"line":40,"column":4},"end":{"line":44,"column":5}},"22":{"start":{"line":41,"column":6},"end":{"line":41,"column":32}},"23":{"start":{"line":43,"column":6},"end":{"line":43,"column":28}},"24":{"start":{"line":48,"column":0},"end":{"line":57,"column":1}},"25":{"start":{"line":49,"column":2},"end":{"line":56,"column":4}},"26":{"start":{"line":50,"column":4},"end":{"line":55,"column":5}},"27":{"start":{"line":51,"column":6},"end":{"line":51,"column":32}},"28":{"start":{"line":53,"column":6},"end":{"line":53,"column":49}},"29":{"start":{"line":54,"column":6},"end":{"line":54,"column":34}},"30":{"start":{"line":59,"column":0},"end":{"line":68,"column":1}},"31":{"start":{"line":60,"column":2},"end":{"line":67,"column":4}},"32":{"start":{"line":61,"column":4},"end":{"line":66,"column":5}},"33":{"start":{"line":62,"column":6},"end":{"line":62,"column":32}},"34":{"start":{"line":64,"column":6},"end":{"line":64,"column":49}},"35":{"start":{"line":65,"column":6},"end":{"line":65,"column":34}},"36":{"start":{"line":70,"column":0},"end":{"line":70,"column":23}}},"branchMap":{"1":{"line":14,"type":"if","locations":[{"start":{"line":14,"column":4},"end":{"line":14,"column":4}},{"start":{"line":14,"column":4},"end":{"line":14,"column":4}}]},"2":{"line":27,"type":"if","locations":[{"start":{"line":27,"column":4},"end":{"line":27,"column":4}},{"start":{"line":27,"column":4},"end":{"line":27,"column":4}}]},"3":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":4},"end":{"line":40,"column":4}},{"start":{"line":40,"column":4},"end":{"line":40,"column":4}}]},"4":{"line":50,"type":"if","locations":[{"start":{"line":50,"column":4},"end":{"line":50,"column":4}},{"start":{"line":50,"column":4},"end":{"line":50,"column":4}}]},"5":{"line":61,"type":"if","locations":[{"start":{"line":61,"column":4},"end":{"line":61,"column":4}},{"start":{"line":61,"column":4},"end":{"line":61,"column":4}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/models/customer.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/models/customer.js","s":{"1":1,"2":1,"3":1,"4":400,"5":1,"6":2,"7":2,"8":0,"9":2,"10":0,"11":2,"12":400,"13":1,"14":1,"15":1,"16":1,"17":1,"18":0,"19":0,"20":0,"21":0,"22":1,"23":0,"24":0,"25":0,"26":1},"b":{"1":[0,2],"2":[0,0],"3":[0,2],"4":[0,0],"5":[1,0],"6":[1,0],"7":[0,0],"8":[0,0]},"f":{"1":400,"2":2,"3":2,"4":400,"5":1,"6":1,"7":0,"8":0,"9":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":28}}},"2":{"name":"(anonymous_2)","line":8,"loc":{"start":{"line":8,"column":15},"end":{"line":8,"column":34}}},"3":{"name":"(anonymous_3)","line":9,"loc":{"start":{"line":9,"column":20},"end":{"line":9,"column":47}}},"4":{"name":"(anonymous_4)","line":15,"loc":{"start":{"line":15,"column":35},"end":{"line":15,"column":54}}},"5":{"name":"(anonymous_5)","line":22,"loc":{"start":{"line":22,"column":16},"end":{"line":22,"column":63}}},"6":{"name":"(anonymous_6)","line":30,"loc":{"start":{"line":30,"column":33},"end":{"line":30,"column":60}}},"7":{"name":"(anonymous_7)","line":36,"loc":{"start":{"line":36,"column":35},"end":{"line":36,"column":54}}},"8":{"name":"(anonymous_8)","line":44,"loc":{"start":{"line":44,"column":19},"end":{"line":44,"column":64}}},"9":{"name":"(anonymous_9)","line":50,"loc":{"start":{"line":50,"column":33},"end":{"line":50,"column":59}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":22}},"3":{"start":{"line":4,"column":0},"end":{"line":6,"column":1}},"4":{"start":{"line":5,"column":2},"end":{"line":5,"column":14}},"5":{"start":{"line":8,"column":0},"end":{"line":20,"column":1}},"6":{"start":{"line":9,"column":2},"end":{"line":19,"column":4}},"7":{"start":{"line":10,"column":4},"end":{"line":18,"column":5}},"8":{"start":{"line":11,"column":6},"end":{"line":11,"column":77}},"9":{"start":{"line":12,"column":11},"end":{"line":18,"column":5}},"10":{"start":{"line":13,"column":6},"end":{"line":13,"column":67}},"11":{"start":{"line":15,"column":6},"end":{"line":17,"column":9}},"12":{"start":{"line":16,"column":8},"end":{"line":16,"column":37}},"13":{"start":{"line":22,"column":0},"end":{"line":42,"column":1}},"14":{"start":{"line":23,"column":2},"end":{"line":28,"column":3}},"15":{"start":{"line":30,"column":2},"end":{"line":41,"column":4}},"16":{"start":{"line":31,"column":4},"end":{"line":40,"column":5}},"17":{"start":{"line":32,"column":6},"end":{"line":32,"column":77}},"18":{"start":{"line":33,"column":11},"end":{"line":40,"column":5}},"19":{"start":{"line":34,"column":6},"end":{"line":34,"column":67}},"20":{"start":{"line":36,"column":6},"end":{"line":39,"column":9}},"21":{"start":{"line":38,"column":8},"end":{"line":38,"column":37}},"22":{"start":{"line":44,"column":0},"end":{"line":62,"column":1}},"23":{"start":{"line":45,"column":2},"end":{"line":48,"column":3}},"24":{"start":{"line":50,"column":2},"end":{"line":61,"column":4}},"25":{"start":{"line":58,"column":8},"end":{"line":58,"column":37}},"26":{"start":{"line":65,"column":0},"end":{"line":65,"column":25}}},"branchMap":{"1":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":4},"end":{"line":10,"column":4}},{"start":{"line":10,"column":4},"end":{"line":10,"column":4}}]},"2":{"line":11,"type":"binary-expr","locations":[{"start":{"line":11,"column":15},"end":{"line":11,"column":20}},{"start":{"line":11,"column":24},"end":{"line":11,"column":65}}]},"3":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":11},"end":{"line":12,"column":11}},{"start":{"line":12,"column":11},"end":{"line":12,"column":11}}]},"4":{"line":13,"type":"binary-expr","locations":[{"start":{"line":13,"column":15},"end":{"line":13,"column":20}},{"start":{"line":13,"column":24},"end":{"line":13,"column":55}}]},"5":{"line":31,"type":"if","locations":[{"start":{"line":31,"column":4},"end":{"line":31,"column":4}},{"start":{"line":31,"column":4},"end":{"line":31,"column":4}}]},"6":{"line":32,"type":"binary-expr","locations":[{"start":{"line":32,"column":15},"end":{"line":32,"column":20}},{"start":{"line":32,"column":24},"end":{"line":32,"column":65}}]},"7":{"line":33,"type":"if","locations":[{"start":{"line":33,"column":11},"end":{"line":33,"column":11}},{"start":{"line":33,"column":11},"end":{"line":33,"column":11}}]},"8":{"line":34,"type":"binary-expr","locations":[{"start":{"line":34,"column":15},"end":{"line":34,"column":20}},{"start":{"line":34,"column":24},"end":{"line":34,"column":55}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/controllers/customers_controller.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/controllers/customers_controller.js","s":{"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":34}}},"2":{"name":"(anonymous_2)","line":7,"loc":{"start":{"line":7,"column":17},"end":{"line":7,"column":44}}},"3":{"name":"(anonymous_3)","line":18,"loc":{"start":{"line":18,"column":8},"end":{"line":18,"column":33}}},"4":{"name":"(anonymous_4)","line":19,"loc":{"start":{"line":19,"column":88},"end":{"line":19,"column":115}}},"5":{"name":"(anonymous_5)","line":30,"loc":{"start":{"line":30,"column":11},"end":{"line":30,"column":36}}},"6":{"name":"(anonymous_6)","line":31,"loc":{"start":{"line":31,"column":61},"end":{"line":31,"column":86}}},"7":{"name":"(anonymous_7)","line":42,"loc":{"start":{"line":42,"column":11},"end":{"line":42,"column":36}}},"8":{"name":"(anonymous_8)","line":43,"loc":{"start":{"line":43,"column":85},"end":{"line":43,"column":110}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":40}},"3":{"start":{"line":4,"column":0},"end":{"line":53,"column":1}},"4":{"start":{"line":7,"column":4},"end":{"line":15,"column":6}},"5":{"start":{"line":8,"column":6},"end":{"line":14,"column":7}},"6":{"start":{"line":9,"column":8},"end":{"line":9,"column":76}},"7":{"start":{"line":10,"column":8},"end":{"line":10,"column":24}},"8":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"9":{"start":{"line":13,"column":8},"end":{"line":13,"column":27}},"10":{"start":{"line":19,"column":4},"end":{"line":27,"column":6}},"11":{"start":{"line":20,"column":6},"end":{"line":26,"column":7}},"12":{"start":{"line":21,"column":8},"end":{"line":21,"column":76}},"13":{"start":{"line":22,"column":8},"end":{"line":22,"column":24}},"14":{"start":{"line":23,"column":8},"end":{"line":23,"column":17}},"15":{"start":{"line":25,"column":8},"end":{"line":25,"column":27}},"16":{"start":{"line":31,"column":4},"end":{"line":39,"column":6}},"17":{"start":{"line":32,"column":6},"end":{"line":38,"column":7}},"18":{"start":{"line":33,"column":8},"end":{"line":33,"column":71}},"19":{"start":{"line":34,"column":8},"end":{"line":34,"column":24}},"20":{"start":{"line":35,"column":8},"end":{"line":35,"column":17}},"21":{"start":{"line":37,"column":8},"end":{"line":37,"column":25}},"22":{"start":{"line":43,"column":4},"end":{"line":51,"column":6}},"23":{"start":{"line":44,"column":6},"end":{"line":50,"column":7}},"24":{"start":{"line":45,"column":8},"end":{"line":45,"column":74}},"25":{"start":{"line":46,"column":8},"end":{"line":46,"column":24}},"26":{"start":{"line":47,"column":8},"end":{"line":47,"column":17}},"27":{"start":{"line":49,"column":8},"end":{"line":49,"column":25}},"28":{"start":{"line":55,"column":0},"end":{"line":55,"column":36}}},"branchMap":{"1":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":6},"end":{"line":8,"column":6}},{"start":{"line":8,"column":6},"end":{"line":8,"column":6}}]},"2":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":6},"end":{"line":20,"column":6}},{"start":{"line":20,"column":6},"end":{"line":20,"column":6}}]},"3":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":6},"end":{"line":32,"column":6}},{"start":{"line":32,"column":6},"end":{"line":32,"column":6}}]},"4":{"line":44,"type":"if","locations":[{"start":{"line":44,"column":6},"end":{"line":44,"column":6}},{"start":{"line":44,"column":6},"end":{"line":44,"column":6}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/controllers/rentals_controller.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/controllers/rentals_controller.js","s":{"1":1,"2":1,"3":1,"4":1,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":1},"b":{"1":[0,0]},"f":{"1":0,"2":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":33}}},"2":{"name":"(anonymous_2)","line":7,"loc":{"start":{"line":7,"column":34},"end":{"line":7,"column":58}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":38}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":44}},"4":{"start":{"line":5,"column":0},"end":{"line":40,"column":1}},"5":{"start":{"line":7,"column":4},"end":{"line":16,"column":6}},"6":{"start":{"line":8,"column":6},"end":{"line":15,"column":7}},"7":{"start":{"line":9,"column":8},"end":{"line":9,"column":73}},"8":{"start":{"line":10,"column":8},"end":{"line":10,"column":24}},"9":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"10":{"start":{"line":14,"column":8},"end":{"line":14,"column":24}},"11":{"start":{"line":42,"column":0},"end":{"line":42,"column":34}}},"branchMap":{"1":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":6},"end":{"line":8,"column":6}},{"start":{"line":8,"column":6},"end":{"line":8,"column":6}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/routes/zomg.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/routes/zomg.js","s":{"1":1,"2":1,"3":1,"4":1,"5":0,"6":1},"b":{},"f":{"1":0},"fnMap":{"1":{"name":"(anonymous_1)","line":30,"loc":{"start":{"line":30,"column":16},"end":{"line":30,"column":41}}}},"statementMap":{"1":{"start":{"line":25,"column":0},"end":{"line":25,"column":33}},"2":{"start":{"line":26,"column":0},"end":{"line":26,"column":30}},"3":{"start":{"line":27,"column":0},"end":{"line":27,"column":15}},"4":{"start":{"line":30,"column":0},"end":{"line":32,"column":3}},"5":{"start":{"line":31,"column":2},"end":{"line":31,"column":44}},"6":{"start":{"line":34,"column":0},"end":{"line":34,"column":24}}},"branchMap":{}}} \ No newline at end of file diff --git a/coverage/lcov-report/VideoStoreAPI/app.js.html b/coverage/lcov-report/VideoStoreAPI/app.js.html index 781994810..801410501 100644 --- a/coverage/lcov-report/VideoStoreAPI/app.js.html +++ b/coverage/lcov-report/VideoStoreAPI/app.js.html @@ -241,7 +241,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html index f9189beec..c602f35b4 100644 --- a/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html +++ b/coverage/lcov-report/VideoStoreAPI/controllers/customers_controller.js.html @@ -214,7 +214,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/index.html b/coverage/lcov-report/VideoStoreAPI/controllers/index.html index 240267f9a..42759e11a 100644 --- a/coverage/lcov-report/VideoStoreAPI/controllers/index.html +++ b/coverage/lcov-report/VideoStoreAPI/controllers/index.html @@ -103,7 +103,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html index 596468122..e4a7db1ca 100644 --- a/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html +++ b/coverage/lcov-report/VideoStoreAPI/controllers/movies_controller.js.html @@ -214,7 +214,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html b/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html index e9aacb9f3..2b7866136 100644 --- a/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html +++ b/coverage/lcov-report/VideoStoreAPI/controllers/rentals_controller.js.html @@ -175,7 +175,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/index.html b/coverage/lcov-report/VideoStoreAPI/index.html index 62f39c3b9..c694025fe 100644 --- a/coverage/lcov-report/VideoStoreAPI/index.html +++ b/coverage/lcov-report/VideoStoreAPI/index.html @@ -77,7 +77,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/models/customer.js.html b/coverage/lcov-report/VideoStoreAPI/models/customer.js.html index 4655368b2..6eb0ee07d 100644 --- a/coverage/lcov-report/VideoStoreAPI/models/customer.js.html +++ b/coverage/lcov-report/VideoStoreAPI/models/customer.js.html @@ -20,24 +20,24 @@

- 50% + 65.38% Statements - 13/26 + 17/26
- 12.5% + 25% Branches - 2/16 + 4/16
- 44.44% + 66.67% Functions - 4/9 + 6/9
- 50% + 65.38% Lines - 13/26 + 17/26
@@ -130,16 +130,16 @@

    -  +             -  -  -  + + +       @@ -194,17 +194,17 @@

}) }   -Customer.sort = function(column_name, columns, n, p, callback) { - var options = { +Customer.sort = function(column_name, columns, n, p, callback) { + var options = { limit : n, offset : p, columns : ["name", "registered_at", "postal_code"], order : column_name }   - db.customers.find({}, options, function(error, customers) { - if(error) { - callback(error || new Error("Could not retrieve customers"), undefined) + db.customers.find({}, options, function(error, customers) { + Eif(error) { + callback(error || new Error("Could not retrieve customers"), undefined) } else if(!customers) { callback(error || new Error("No customers found"), undefined) } else { @@ -244,7 +244,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/models/index.html b/coverage/lcov-report/VideoStoreAPI/models/index.html index 2d044f09c..1b10c130d 100644 --- a/coverage/lcov-report/VideoStoreAPI/models/index.html +++ b/coverage/lcov-report/VideoStoreAPI/models/index.html @@ -20,24 +20,24 @@

- 35.71% + 40.48% Statements - 30/84 + 34/84
- 4.76% + 9.52% Branches - 2/42 + 4/42
- 14.81% + 22.22% Functions - 4/27 + 6/27
- 35.71% + 40.48% Lines - 30/84 + 34/84
@@ -60,15 +60,15 @@

customer.js -
- 50% - 13/26 - 12.5% - 2/16 - 44.44% - 4/9 - 50% - 13/26 +
+ 65.38% + 17/26 + 25% + 4/16 + 66.67% + 6/9 + 65.38% + 17/26 @@ -103,7 +103,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/models/movie.js.html b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html index e87543541..66a910e92 100644 --- a/coverage/lcov-report/VideoStoreAPI/models/movie.js.html +++ b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html @@ -175,7 +175,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/models/rental.js.html b/coverage/lcov-report/VideoStoreAPI/models/rental.js.html index 4bfad9f77..c21cc15b6 100644 --- a/coverage/lcov-report/VideoStoreAPI/models/rental.js.html +++ b/coverage/lcov-report/VideoStoreAPI/models/rental.js.html @@ -259,7 +259,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/routes/index.html b/coverage/lcov-report/VideoStoreAPI/routes/index.html index 4d742a053..369ef5218 100644 --- a/coverage/lcov-report/VideoStoreAPI/routes/index.html +++ b/coverage/lcov-report/VideoStoreAPI/routes/index.html @@ -90,7 +90,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/routes/index.js.html b/coverage/lcov-report/VideoStoreAPI/routes/index.js.html index 3a6544cd0..ad37764a9 100644 --- a/coverage/lcov-report/VideoStoreAPI/routes/index.js.html +++ b/coverage/lcov-report/VideoStoreAPI/routes/index.js.html @@ -268,7 +268,7 @@

diff --git a/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html b/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html index 5873d2d55..414ba745a 100644 --- a/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html +++ b/coverage/lcov-report/VideoStoreAPI/routes/zomg.js.html @@ -151,7 +151,7 @@

diff --git a/coverage/lcov-report/index.html b/coverage/lcov-report/index.html index 58de4f051..b25aa675f 100644 --- a/coverage/lcov-report/index.html +++ b/coverage/lcov-report/index.html @@ -20,24 +20,24 @@

- 41.52% + 43.3% Statements - 93/224 + 97/224
- 4.55% + 7.58% Branches - 3/66 + 5/66
- 6.35% + 9.52% Functions - 4/63 + 6/63
- 41.52% + 43.3% Lines - 93/224 + 97/224
@@ -86,15 +86,15 @@

VideoStoreAPI/models/ -
- 35.71% - 30/84 - 4.76% - 2/42 - 14.81% - 4/27 - 35.71% - 30/84 +
+ 40.48% + 34/84 + 9.52% + 4/42 + 22.22% + 6/27 + 40.48% + 34/84 @@ -116,7 +116,7 @@

diff --git a/coverage/lcov.info b/coverage/lcov.info new file mode 100644 index 000000000..b9ed8f125 --- /dev/null +++ b/coverage/lcov.info @@ -0,0 +1,497 @@ +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/app.js +FN:36,(anonymous_1) +FN:47,(anonymous_2) +FN:58,(anonymous_3) +FNF:3 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:8,1 +DA:9,1 +DA:11,1 +DA:13,1 +DA:14,1 +DA:17,1 +DA:18,1 +DA:20,1 +DA:22,1 +DA:26,1 +DA:27,1 +DA:28,1 +DA:29,1 +DA:30,1 +DA:32,1 +DA:33,1 +DA:36,1 +DA:37,0 +DA:38,0 +DA:39,0 +DA:46,1 +DA:47,0 +DA:48,0 +DA:49,0 +DA:58,1 +DA:59,0 +DA:60,0 +LF:33 +LH:25 +BRDA:46,1,0,0 +BRDA:46,1,1,1 +BRDA:48,2,0,0 +BRDA:48,2,1,0 +BRDA:59,3,0,0 +BRDA:59,3,1,0 +BRF:6 +BRH:1 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/routes/index.js +FN:7,(anonymous_1) +FN:11,(anonymous_2) +FN:15,(anonymous_3) +FN:20,(anonymous_4) +FN:24,(anonymous_5) +FN:28,(anonymous_6) +FN:32,(anonymous_7) +FN:36,(anonymous_8) +FN:41,(anonymous_9) +FN:47,(anonymous_10) +FN:52,(anonymous_11) +FN:57,(anonymous_12) +FN:62,(anonymous_13) +FN:67,(anonymous_14) +FNF:14 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +FNDA:0,(anonymous_12) +FNDA:0,(anonymous_13) +FNDA:0,(anonymous_14) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:7,1 +DA:8,0 +DA:11,1 +DA:12,0 +DA:15,1 +DA:16,0 +DA:19,1 +DA:21,0 +DA:24,1 +DA:25,0 +DA:28,1 +DA:29,0 +DA:32,1 +DA:33,0 +DA:36,1 +DA:37,0 +DA:40,1 +DA:42,0 +DA:46,1 +DA:48,0 +DA:51,1 +DA:53,0 +DA:56,1 +DA:58,0 +DA:61,1 +DA:63,0 +DA:66,1 +DA:68,0 +DA:73,1 +LF:34 +LH:20 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/controllers/movies_controller.js +FN:6,(anonymous_1) +FN:7,(anonymous_2) +FN:18,(anonymous_3) +FN:19,(anonymous_4) +FN:30,(anonymous_5) +FN:31,(anonymous_6) +FN:42,(anonymous_7) +FN:43,(anonymous_8) +FNF:8 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +DA:1,1 +DA:2,1 +DA:4,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:13,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:37,0 +DA:43,0 +DA:44,0 +DA:45,0 +DA:46,0 +DA:47,0 +DA:49,0 +DA:55,1 +LF:28 +LH:4 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRDA:20,2,0,0 +BRDA:20,2,1,0 +BRDA:32,3,0,0 +BRDA:32,3,1,0 +BRDA:44,4,0,0 +BRDA:44,4,1,0 +BRF:8 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/models/movie.js +FN:4,(anonymous_1) +FN:8,(anonymous_2) +FN:9,(anonymous_3) +FN:15,(anonymous_4) +FN:22,(anonymous_5) +FN:29,(anonymous_6) +FN:35,(anonymous_7) +FNF:7 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +DA:1,1 +DA:2,1 +DA:4,1 +DA:5,0 +DA:8,1 +DA:9,0 +DA:10,0 +DA:11,0 +DA:12,0 +DA:13,0 +DA:15,0 +DA:16,0 +DA:22,1 +DA:23,0 +DA:29,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:35,0 +DA:36,0 +DA:42,1 +LF:22 +LH:6 +BRDA:10,1,0,0 +BRDA:10,1,1,0 +BRDA:11,2,0,0 +BRDA:11,2,1,0 +BRDA:12,3,0,0 +BRDA:12,3,1,0 +BRDA:13,4,0,0 +BRDA:13,4,1,0 +BRDA:30,5,0,0 +BRDA:30,5,1,0 +BRDA:31,6,0,0 +BRDA:31,6,1,0 +BRDA:32,7,0,0 +BRDA:32,7,1,0 +BRDA:33,8,0,0 +BRDA:33,8,1,0 +BRF:16 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/models/rental.js +FN:6,(anonymous_1) +FN:10,(anonymous_2) +FN:11,(anonymous_3) +FN:22,(anonymous_4) +FN:26,(anonymous_5) +FN:35,(anonymous_6) +FN:39,(anonymous_7) +FN:48,(anonymous_8) +FN:49,(anonymous_9) +FN:59,(anonymous_10) +FN:60,(anonymous_11) +FNF:11 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:6,1 +DA:7,0 +DA:10,1 +DA:11,0 +DA:14,0 +DA:15,0 +DA:17,0 +DA:22,1 +DA:23,0 +DA:26,0 +DA:27,0 +DA:28,0 +DA:30,0 +DA:35,1 +DA:36,0 +DA:39,0 +DA:40,0 +DA:41,0 +DA:43,0 +DA:48,1 +DA:49,0 +DA:50,0 +DA:51,0 +DA:53,0 +DA:54,0 +DA:59,1 +DA:60,0 +DA:61,0 +DA:62,0 +DA:64,0 +DA:65,0 +DA:70,1 +LF:36 +LH:11 +BRDA:14,1,0,0 +BRDA:14,1,1,0 +BRDA:27,2,0,0 +BRDA:27,2,1,0 +BRDA:40,3,0,0 +BRDA:40,3,1,0 +BRDA:50,4,0,0 +BRDA:50,4,1,0 +BRDA:61,5,0,0 +BRDA:61,5,1,0 +BRF:10 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/models/customer.js +FN:4,(anonymous_1) +FN:8,(anonymous_2) +FN:9,(anonymous_3) +FN:15,(anonymous_4) +FN:22,(anonymous_5) +FN:30,(anonymous_6) +FN:36,(anonymous_7) +FN:44,(anonymous_8) +FN:50,(anonymous_9) +FNF:9 +FNH:6 +FNDA:400,(anonymous_1) +FNDA:2,(anonymous_2) +FNDA:2,(anonymous_3) +FNDA:400,(anonymous_4) +FNDA:1,(anonymous_5) +FNDA:1,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +DA:1,1 +DA:2,1 +DA:4,1 +DA:5,400 +DA:8,1 +DA:9,2 +DA:10,2 +DA:11,0 +DA:12,2 +DA:13,0 +DA:15,2 +DA:16,400 +DA:22,1 +DA:23,1 +DA:30,1 +DA:31,1 +DA:32,1 +DA:33,0 +DA:34,0 +DA:36,0 +DA:38,0 +DA:44,1 +DA:45,0 +DA:50,0 +DA:58,0 +DA:65,1 +LF:26 +LH:17 +BRDA:10,1,0,0 +BRDA:10,1,1,2 +BRDA:11,2,0,0 +BRDA:11,2,1,0 +BRDA:12,3,0,0 +BRDA:12,3,1,2 +BRDA:13,4,0,0 +BRDA:13,4,1,0 +BRDA:31,5,0,1 +BRDA:31,5,1,0 +BRDA:32,6,0,1 +BRDA:32,6,1,0 +BRDA:33,7,0,0 +BRDA:33,7,1,0 +BRDA:34,8,0,0 +BRDA:34,8,1,0 +BRF:16 +BRH:4 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/controllers/customers_controller.js +FN:6,(anonymous_1) +FN:7,(anonymous_2) +FN:18,(anonymous_3) +FN:19,(anonymous_4) +FN:30,(anonymous_5) +FN:31,(anonymous_6) +FN:42,(anonymous_7) +FN:43,(anonymous_8) +FNF:8 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +DA:1,1 +DA:2,1 +DA:4,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:13,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:37,0 +DA:43,0 +DA:44,0 +DA:45,0 +DA:46,0 +DA:47,0 +DA:49,0 +DA:55,1 +LF:28 +LH:4 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRDA:20,2,0,0 +BRDA:20,2,1,0 +BRDA:32,3,0,0 +BRDA:32,3,1,0 +BRDA:44,4,0,0 +BRDA:44,4,1,0 +BRF:8 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/controllers/rentals_controller.js +FN:6,(anonymous_1) +FN:7,(anonymous_2) +FNF:2 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:14,0 +DA:42,1 +LF:11 +LH:5 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRF:2 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/routes/zomg.js +FN:30,(anonymous_1) +FNF:1 +FNH:0 +FNDA:0,(anonymous_1) +DA:25,1 +DA:26,1 +DA:27,1 +DA:30,1 +DA:31,0 +DA:34,1 +LF:6 +LH:5 +BRF:0 +BRH:0 +end_of_record diff --git a/package.json b/package.json index 579cae322..8719e6170 100644 --- a/package.json +++ b/package.json @@ -4,13 +4,13 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/", + "test": "istanbul cover --include-all-sources jasmine-node test", "db:drop": "dropdb video-store-api", "db:create": "createdb video-store-api", "db:schema": "node tasks/load_schema.js", "db:seed": "node tasks/seed.js", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", - "test": "istanbul cover --include-all-sources jasmine-node test" + "test": "clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/" }, "dependencies": { "body-parser": "~1.13.2", diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 043a9f5d7..2f9a29263 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -2,45 +2,107 @@ var request = require('request') var base_url = "http://localhost:3000/customers" -describe("Endpoint at /customers", function () { - it('responds with a 200 status code', function (done) { - request.get(base_url, function(error, response, body) { - expect(response.statusCode).toEqual(200) - done() +describe("#index", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers", function(error, response, body) { + expect(response.statusCode).toBe(200) + done() + }) }) - }) - describe("the returned json data", function() { - it('has the right keys', function(done) { - request.get(base_url, function(error, response, body) { - var customers = JSON.parse(body)[0]["id"] - expect(Object.keys(customers)).toEqual(['id','name','registered_at', 'address', 'city', 'state', 'postal_code', 'phone', 'account_credit']) + + it("should be json", function(done) { + request.get("http://localhost:3000/customers", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers", function(error, response, body) { + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') done() }) }) +}) - it('has the right values for the keys', function(done) { - request.get(base_url, function(error, response, body) { - var customers = JSON.parse(body)[0]["id"] - expect(customers.name).toEqual('Shelley Rocha') +describe("#sort", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers/sort/id", function(error, response, body) { + expect(response.statusCode).toBe(200) done() }) }) - it('Endpoint at customers/15/current', function(done){ - request.get("http://localhost:3000/customers/45/current", function(error,response, body){ + it("should be json", function(done) { + request.get("http://localhost:3000/customers/sort/id", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers/sort/id", function(error, response, body) { var customers = JSON.parse(body) - expect(response.statusCode).toEqual(200) + expect(typeof customers).toEqual('object') + done() + }) + }) + +}) + + + +describe("#current", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers/12/current", function(error, response, body) { + expect(response.statusCode).toBe(200) done() }) }) - it('should be an array of objects', function(done){ - request.get(base_url,function(error,response,body){ + it("should be json", function(done) { + request.get("http://localhost:3000/customers/12/current", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers/12/current", function(error, response, body) { var customers = JSON.parse(body) expect(typeof customers).toEqual('object') done() }) }) + }) -}) + + + describe("#history", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers/47/history", function(error, response, body) { + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("should be json", function(done) { + request.get("http://localhost:3000/customers/47/history", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers/47/history", function(error, response, body) { + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') + done() + }) + }) + + }) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js new file mode 100644 index 000000000..19c337935 --- /dev/null +++ b/spec/models/customer.spec.js @@ -0,0 +1,45 @@ +var app = require('../../app') +var db = app.get('db') +var Customer = require('../../models/customer') + +describe('Customer', function () { + beforeEach(function(){ + + }) + + afterEach(function () { + db.end() + }) + + + describe('#all', function () { + it('should return an array of objects', function(done) { + Customer.all(function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + + }) + + it('should retern the right amount of customers', function(done) { + Customer.all(function(error,customers){ + expect(customers.length).toBeGreaterThan(199) + done() + }) + }) + + }) + + describe("#sort", function(){ + it('should return an array of objects', function(done){ + Customer.sort(['name',1,30],function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + }) + }) + }) + + + + + +}) From acdd33945eb125cbd9132f02e0d229295edbf86d Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 11:14:28 -0700 Subject: [PATCH 38/46] dependency injection attempt halp --- controllers/rentals_controller.js | 9 +++++--- models/rental.js | 34 ++++++++++++++++++------------- routes/index.js | 4 ++-- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js index d9ce7b055..b354272ac 100644 --- a/controllers/rentals_controller.js +++ b/controllers/rentals_controller.js @@ -27,10 +27,13 @@ var RentalsController = { }) }, - check_out: function(req, res, next) { - Rental.check_out(req.params.title, req.params.customer_id, function(error, check_out) { + check_out: function(req, res) { + var title = req.params.title + var customer_id = req.params.customer_id + + Rental.check_out(title, customer_id, function(error, result, next) { if(error) { - var err = new Error("Error retrieving customers:\n" + error.message) + var err = new Error("Error completing rental:\n" + error.message) err.status = 500 next(err) } else { diff --git a/models/rental.js b/models/rental.js index 2fa47bb03..206e6fda7 100644 --- a/models/rental.js +++ b/models/rental.js @@ -29,13 +29,25 @@ Rental.customers = function(title, callback) { }) } + Rental.check_out = function(title, customer_id, callback) { var today = new Date() var today_plus_two = new Date(today) today_plus_two.setDate(today_plus_two.getDate() + 2) + Rental.get_movie_id(title, customer_id, callback) +} - var movie_id = db.run("SELECT id FROM rentals WHERE title = $1 LIMIT 1", [title]) +Rental.get_movie_id = function (title, customer_id, callback) { + db.run("SELECT movie_id FROM rentals WHERE title = $1 LIMIT 1", [title], function(error, res) + { + var movie_id = res.movie_id + if (error) { callback(error, undefined) } + }) + Rental.new_rental(movie_id, customer_id, title, callback) + Rental.charge_customer(movie_id, customer_id, title, callback) +} +Rental.new_rental = function (movie_id, customer_id, title, callback) { db.rentals.save({ movie_id: movie_id, customer_id: customer_id, @@ -43,21 +55,15 @@ Rental.check_out = function(title, customer_id, callback) { checkout_date: today, due_date: today_plus_two, returned_date: null - } - // , function (error, rental) { - // if (error) { - // callback(error, undefined) - // } - // callback(null, rental) - // } -) + }, + function (error, rental) { + if (error) { callback(error, undefined) } + }) +} +Rental.charge_customer = function (movie_id, customer_id, title, callback) { db.run("UPDATE customers SET account_credit=account_credit-4 WHERE id=$1;", [customer_id], function (error, charged) { - if (error) { - callback(error, undefined); - } else { - callback(null, charged) - } + if (error) { callback(error, undefined) } }) } diff --git a/routes/index.js b/routes/index.js index 1b7f5b3f1..ea4ba1fcf 100644 --- a/routes/index.js +++ b/routes/index.js @@ -53,12 +53,12 @@ function(req, res, next) { rentals_controller.customers(req, res, next) }) -router.get('/rentals/:title/check-out/:id', +router.get('/rentals/:title/check-out/:customer_id', function(req, res, next) { rentals_controller.check_out(req, res, next) }) -router.get('/rentals/:title/return/:id', +router.get('/rentals/:title/return/:customer_id', function(req, res, next) { rentals_controller.return(req, res, next) }) From c611fe864f2342d2c2ba909dba51c1057e8e8298 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 13:45:19 -0700 Subject: [PATCH 39/46] successfully saving new rental! --- models/rental.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/models/rental.js b/models/rental.js index 206e6fda7..bc51b42a3 100644 --- a/models/rental.js +++ b/models/rental.js @@ -29,25 +29,34 @@ Rental.customers = function(title, callback) { }) } - Rental.check_out = function(title, customer_id, callback) { - var today = new Date() - var today_plus_two = new Date(today) - today_plus_two.setDate(today_plus_two.getDate() + 2) Rental.get_movie_id(title, customer_id, callback) + console.log("got to Rental.checkout") } Rental.get_movie_id = function (title, customer_id, callback) { db.run("SELECT movie_id FROM rentals WHERE title = $1 LIMIT 1", [title], function(error, res) { - var movie_id = res.movie_id - if (error) { callback(error, undefined) } + // console.(res.movie_id) + // var movie_id = res.movie_id + if (error) { + callback(error, undefined) + } else { + movie_id = res[0]["movie_id"] + Rental.new_rental(movie_id, customer_id, title, callback) + Rental.charge_customer(movie_id, customer_id, title, callback) + } }) - Rental.new_rental(movie_id, customer_id, title, callback) - Rental.charge_customer(movie_id, customer_id, title, callback) } Rental.new_rental = function (movie_id, customer_id, title, callback) { + console.log("movie_id: " + movie_id) + console.log("customer_id " + customer_id) + console.log("title " + title) + var today = new Date() + var today_plus_two = new Date(today) + today_plus_two.setDate(today_plus_two.getDate() + 2) + db.rentals.save({ movie_id: movie_id, customer_id: customer_id, From 0c80a7fdd725d5efd2a42856dc28e6ddf746a6b7 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 13:48:12 -0700 Subject: [PATCH 40/46] fixing customers callback hopefully --- models/customer.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/models/customer.js b/models/customer.js index d5bfc56f0..476a1ad0f 100644 --- a/models/customer.js +++ b/models/customer.js @@ -48,18 +48,12 @@ Customer.find_id = function(customer_ids, column_name, columns) { } db.customers.find({}, options, function(error, customer) { - // if(error) { - // callback(error || new Error("Could not retrieve customers"), undefined) - // } else if(!customers) { - // callback(error || new Error("No customers found"), undefined) - // } else { - // callback(null, customers.map(function(customer) { - // console.log(customer) - return new Customer(customer) - // })) - // } + if(error) { + callback(error, undefined) + } else { + callback(null, customers) + } }) } - module.exports = Customer From 5bc0bce7daf9b99bd50d8a7185b6f74b2c7e8ec9 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 24 Jun 2016 13:48:40 -0700 Subject: [PATCH 41/46] working on customers test --- spec/models/customer.spec.js | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index 19c337935..b61ffc405 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -32,10 +32,51 @@ describe('Customer', function () { describe("#sort", function(){ it('should return an array of objects', function(done){ - Customer.sort(['name',1,30],function(error,customers){ + Customer.sort('name',10,5,3,function(error,customers){ expect(customers).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain lenght', function(done){ + Customer.sort('name',10,5,3, function(error,customers){ + expect(customers.length).toEqual(5) + done() + }) + }) + + it('it must sort by name', function(done){ + Customer.sort('name',10,5,3, function(error,customers){ + expect(customers[0]['id']['name']).toEqual('Acton Gilliam') + done() + }) + }) + + + it('if must be an address', function(done){ + Customer.sort('address',10,5,3, function(error,customers){ + expect(customers[0]['id']['address']).toEqual('121 Porta Ave') + done() }) }) + + it('should give an error if column does not exist', function(done){ + Customer.sort('candy',10,5,3, function(error,customers){ + expect(error.message).toEqual('column "candy" does not exist') + done() + }) + }) + + }) + + describe("#find_id", function(){ + it('should return an array of objects', function(done){ + Customer.find_id(1,10,name,function(error,customers){ + expect(customers).toEqual('name') + done() + }) + }) + }) From 834c6ba33a4808f423d02ba3d336b27ac7b116bd Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 14:27:45 -0700 Subject: [PATCH 42/46] checkout function is done! complete with fancy on-purpose status code. --- controllers/rentals_controller.js | 3 ++- models/rental.js | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js index b354272ac..cb8ee3d51 100644 --- a/controllers/rentals_controller.js +++ b/controllers/rentals_controller.js @@ -37,7 +37,8 @@ var RentalsController = { err.status = 500 next(err) } else { - res.json(check_out) + res.json(result) + res.statusCode = 204 } }) } diff --git a/models/rental.js b/models/rental.js index bc51b42a3..81d70ebb7 100644 --- a/models/rental.js +++ b/models/rental.js @@ -31,14 +31,11 @@ Rental.customers = function(title, callback) { Rental.check_out = function(title, customer_id, callback) { Rental.get_movie_id(title, customer_id, callback) - console.log("got to Rental.checkout") } Rental.get_movie_id = function (title, customer_id, callback) { db.run("SELECT movie_id FROM rentals WHERE title = $1 LIMIT 1", [title], function(error, res) { - // console.(res.movie_id) - // var movie_id = res.movie_id if (error) { callback(error, undefined) } else { @@ -50,9 +47,6 @@ Rental.get_movie_id = function (title, customer_id, callback) { } Rental.new_rental = function (movie_id, customer_id, title, callback) { - console.log("movie_id: " + movie_id) - console.log("customer_id " + customer_id) - console.log("title " + title) var today = new Date() var today_plus_two = new Date(today) today_plus_two.setDate(today_plus_two.getDate() + 2) @@ -71,8 +65,12 @@ Rental.new_rental = function (movie_id, customer_id, title, callback) { } Rental.charge_customer = function (movie_id, customer_id, title, callback) { - db.run("UPDATE customers SET account_credit=account_credit-4 WHERE id=$1;", [customer_id], function (error, charged) { - if (error) { callback(error, undefined) } + db.run("UPDATE customers SET account_credit = account_credit-4 WHERE id=$1", [customer_id], function (error, charged) { + if (error) { + callback(error, undefined) + } else { + callback(null, charged) + } }) } From 04d878797bbe9cebda1cbbe376a93c7d8e745684 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 24 Jun 2016 14:47:29 -0700 Subject: [PATCH 43/46] controller test for some reason are not working --- spec/models/customer.spec.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index b61ffc405..119c37bad 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -69,18 +69,4 @@ describe('Customer', function () { }) - describe("#find_id", function(){ - it('should return an array of objects', function(done){ - Customer.find_id(1,10,name,function(error,customers){ - expect(customers).toEqual('name') - done() - }) - }) - - }) - - - - - }) From 9c28dad85c16dce8abc19b0240f2f6f12761e431 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 14:57:35 -0700 Subject: [PATCH 44/46] trying to get return rental going --- controllers/rentals_controller.js | 15 +++++++++++++++ models/customer.js | 2 +- models/rental.js | 11 +++++++++++ routes/index.js | 2 +- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js index cb8ee3d51..829b9ad8c 100644 --- a/controllers/rentals_controller.js +++ b/controllers/rentals_controller.js @@ -41,6 +41,21 @@ var RentalsController = { res.statusCode = 204 } }) + }, + + return_rental: function(req, res) { + console.log("request: " + res) + + Rental.return_rental(title, customer_id, function(error, result, next) { + if(error) { + var err = new Error("Error completing rental:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(result) + res.statusCode = 204 + } + }) } } diff --git a/models/customer.js b/models/customer.js index 476a1ad0f..b9a4ccf7c 100644 --- a/models/customer.js +++ b/models/customer.js @@ -51,7 +51,7 @@ Customer.find_id = function(customer_ids, column_name, columns) { if(error) { callback(error, undefined) } else { - callback(null, customers) + callback(null, customer) } }) } diff --git a/models/rental.js b/models/rental.js index 81d70ebb7..6ce3152c3 100644 --- a/models/rental.js +++ b/models/rental.js @@ -74,6 +74,17 @@ Rental.charge_customer = function (movie_id, customer_id, title, callback) { }) } +Rental.return_rental = function (title, customer_id, callback) { + var today = new Date() + db.run("UPDATE rentals SET returned_date = $1 WHERE customer_id::int = $2", [today, customer_id], function(error, result) { + if (error) { + callback(error, undefined) + } else { + callback(null, result) + } + }) +} + Rental.current_title = function(title, columns, callback) { var options = { columns : ['name', 'phone', 'account_credit'] diff --git a/routes/index.js b/routes/index.js index ea4ba1fcf..bc34b7b3c 100644 --- a/routes/index.js +++ b/routes/index.js @@ -60,7 +60,7 @@ function(req, res, next) { router.get('/rentals/:title/return/:customer_id', function(req, res, next) { - rentals_controller.return(req, res, next) + rentals_controller.return_rental(req, res, next) }) router.get('/rentals/overdue', From 3fbb6760cc58adbe373d640cfb96636d7b8842a9 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 15:14:48 -0700 Subject: [PATCH 45/46] doing some api stuff --- views/docs.html | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/views/docs.html b/views/docs.html index 3961cc152..561567e5a 100644 --- a/views/docs.html +++ b/views/docs.html @@ -1,6 +1,42 @@ + -

docs!

+ +

Video Store API - Endpoints

+ +
    +
  • +

    Movies

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    EndpointHTTP VerbNotes
    /moviesGET
    /movies/sort/:column_nameGETSort params: title, release date
    /movies/:title/currentGETReturns current renters' name, phone number, account credit
    /movies/:title/history/sort/:column_nameGETReturns past renters' name, phone number, account credit- sort by customer name or check out date
    +
  • + + From f174495a1a1c32a6c891702ea4ada696297ad70e Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 24 Jun 2016 15:46:53 -0700 Subject: [PATCH 46/46] api mostly done --- routes/index.js | 2 +- views/docs.html | 125 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/routes/index.js b/routes/index.js index bc34b7b3c..baf891ab3 100644 --- a/routes/index.js +++ b/routes/index.js @@ -58,7 +58,7 @@ function(req, res, next) { rentals_controller.check_out(req, res, next) }) -router.get('/rentals/:title/return/:customer_id', +router.post('/rentals/:title/return/:customer_id', function(req, res, next) { rentals_controller.return_rental(req, res, next) }) diff --git a/views/docs.html b/views/docs.html index 561567e5a..36d70ab2f 100644 --- a/views/docs.html +++ b/views/docs.html @@ -1,10 +1,9 @@ -

    docs!

    -

    Video Store API - Endpoints

    +

    Video Store API

    • @@ -13,30 +12,152 @@

      Movies

      Endpoint HTTP Verb + Required Params + Optional Params Notes /movies GET + None + None /movies/sort/:column_name GET + Must include one of the sort params + Can include n (number of results) or p (offset) Sort params: title, release date /movies/:title/current GET + Movie title + None Returns current renters' name, phone number, account credit /movies/:title/history/sort/:column_name GET + Movie title, one of two sort params + None Returns past renters' name, phone number, account credit- sort by customer name or check out date
    • +
    • +

      Customers

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      EndpointHTTP VerbRequired ParamsOptional ParamsNotes
      /customersGETNoneNone
      /customers/sort/:column_nameGETOne of the three sort paramsCan include n (number of results) or p (offset)Sort params: name, registered at, postal code
      /customers/:id/currentGETCustomer idNoneReturns movies the customer currently had checked out
      /customers/:id/historyGETCustomer idNoneReturns movies customer has checked out in the past. Sort params: check out date, return date
      +
    • +
    • +

      Rentals

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      EndpointHTTP VerbRequired ParamsOptional ParamsNotes
      /rentals/:titleGETTitleNone
      /rentals/:title/customersGETTitleNone
      /rentals/:title/check-out/:customer_idGETTitle and customer_idNoneCreates new rental record with appropriate customer & movie data, charges customer for rental. Successful response yields 204 key- this request modifies the database, but returns no data to the controller.
      /rentals/:title/return/:customer_idPOSTUnfinished
      /rentals/overdueGETUnfinished
      +
    • +
    • +

      Docs

      + + + + + + + + + + + + + + + + + + + + + + +
      EndpointHTTP VerbRequired ParamsOptional ParamsNotes
      /api/docsGETNoneNoneYou're looking at it!
      /api/docs.jsonGETNoneNoneUnfinished - would render this page's info in JSON.
      +