From 1f9bb096aff841bbeef9be7e5e1880d5978df6e1 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Tue, 14 Jun 2016 14:44:22 -0700 Subject: [PATCH 01/79] added customers and movies route files --- routes/customers.js | 9 +++++++++ routes/movies.js | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 routes/customers.js create mode 100644 routes/movies.js diff --git a/routes/customers.js b/routes/customers.js new file mode 100644 index 000000000..06cfc1137 --- /dev/null +++ b/routes/customers.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.status(200).json({whatevs: 'whatevs!!!'}) +}); + +module.exports = router; diff --git a/routes/movies.js b/routes/movies.js new file mode 100644 index 000000000..06cfc1137 --- /dev/null +++ b/routes/movies.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.status(200).json({whatevs: 'whatevs!!!'}) +}); + +module.exports = router; From e3ccafed8473d631a4f666b039241ad770d28616 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Tue, 14 Jun 2016 14:45:01 -0700 Subject: [PATCH 02/79] added movies and customers routes to app.js --- app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app.js b/app.js index f0579b1dc..0c554aead 100644 --- a/app.js +++ b/app.js @@ -6,6 +6,14 @@ var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var routes = require('./routes/index'); +var app = express(); + +// divide responsibilities. everything in "movies" will have /movies in its url. +var movies = require('./routes/movies'); +app.use('/movies', movies) + +var customers = require('./routes/customers'); +app.use('/customers', customers) var app = express(); From 86d87077f60410be17d0c7389e5fc86d1ab20f48 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Tue, 14 Jun 2016 14:45:13 -0700 Subject: [PATCH 03/79] moved something --- app.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/app.js b/app.js index 0c554aead..463460ff1 100644 --- a/app.js +++ b/app.js @@ -15,8 +15,6 @@ app.use('/movies', movies) var customers = require('./routes/customers'); app.use('/customers', customers) -var app = express(); - // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); From 3aac48f7cfb7f21510dda662d5fd547a1fb4f47d Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Tue, 14 Jun 2016 14:45:29 -0700 Subject: [PATCH 04/79] tested zomg route and it worked --- routes/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/index.js b/routes/index.js index 06cfc1137..c0b19478f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,4 +6,8 @@ router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) }); +router.get('/zomg', function(req, res, next) { + res.status(200).json({whatevs: 'it works!!!'}) +}); + module.exports = router; From 2d87356960f030968d9d425c169b8f16ac709876 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 15:34:07 -0700 Subject: [PATCH 05/79] Added massive to npm, and gave it wave1 scripts --- package.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d39b26403..cd18c6d29 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,12 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/" + "test": "clear; jasmine-node --verbose spec/", + "db:create": "createdb massive", + "db:seed": "clear; node tasks/db_seed.js", + "db:drop": "dropdb massive", + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema", + "db:schema": "clear; node tasks/load_schema.js" }, "dependencies": { "body-parser": "~1.13.2", @@ -12,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" From 3125a51d8bd1859ba00023925f7737df4067715e Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 15:34:32 -0700 Subject: [PATCH 06/79] single route change /sort --- routes/customers.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routes/customers.js b/routes/customers.js index 06cfc1137..4c3397ddd 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -1,9 +1,9 @@ -var express = require('express'); -var router = express.Router(); +var express = require('express') +var router = express.Router() /* GET home page. */ -router.get('/', function(req, res, next) { +router.get('/sort/', function (req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) -}); +}) -module.exports = router; +module.exports = router From 085fa3db56c329651b80f7a1ca21b0137284a5de Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 15:45:00 -0700 Subject: [PATCH 07/79] db/setup schema --- db/setup/schema.sql | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 db/setup/schema.sql diff --git a/db/setup/schema.sql b/db/setup/schema.sql new file mode 100644 index 000000000..47d1fd59b --- /dev/null +++ b/db/setup/schema.sql @@ -0,0 +1,38 @@ +DROP TABLE IF EXISTS customers; +CREATE TABLE customers( + id serial PRIMARY KEY, + name text, + address text, + city text, + state text, + postal_code text, + phone text, + account_credit integer, + registered_at date +); + +-- CREATE INDEX words_word ON words (word); FIX THIS, I HAVE NO IDEA WHAT INDEX + +DROP TABLE IF EXISTS movies; +CREATE TABLE movies( + id serial PRIMARY KEY, + title text, + overview text, + inventory integer, + available integer, + release_date date +); + +-- CREATE INDEX words_word ON words (word); FIX THIS, I HAVE NO IDEA WHAT INDEX + +DROP TABLE IF EXISTS rentals; +CREATE TABLE rentals( + id serial PRIMARY KEY, + customer_id integer, + movie_id integer, + check_out_date date, + checked_out boolean, + due_date date +); + +-- CREATE INDEX words_word ON words (word); FIX THIS, I HAVE NO IDEA WHAT INDEX From 628948249d9f306cc3f7a9dec2546fdf96dd9999 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 15:45:36 -0700 Subject: [PATCH 08/79] load schema and (non functional) seeding tasks --- tasks/db_seed.js | 24 ++++++++++++++++++++++++ tasks/load_schema.js | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tasks/db_seed.js create mode 100644 tasks/load_schema.js diff --git a/tasks/db_seed.js b/tasks/db_seed.js new file mode 100644 index 000000000..f752e140e --- /dev/null +++ b/tasks/db_seed.js @@ -0,0 +1,24 @@ +var massive = require('massive') +var connectionString = 'postgres://localhost/massive' +var customerSeed = require('../db/seeds/customers') +var movieSeed = require('../db/seeds/movies') + +var db = massive.connectSync({connectionString: connectionString}) + +db.seed.customers([customerSeed], function (err, res) { + if (err) { + throw (new Error(err.message)) + } + + console.log('schema!') + process.exit() +}) + +db.seed.movies([movieSeed], function (err, res) { + if (err) { + throw (new Error(err.message)) + } + + console.log('schema!') + process.exit() +}) diff --git a/tasks/load_schema.js b/tasks/load_schema.js new file mode 100644 index 000000000..7735e86e8 --- /dev/null +++ b/tasks/load_schema.js @@ -0,0 +1,21 @@ +var massive = require('massive') +var connectionString = 'postgres://localhost/massive' + +var db = massive.connectSync({connectionString: connectionString}) + +db.setup.schema([], function (err, res) { + if (err) { + throw (new Error(err.message)) + } + + console.log('schema!') + process.exit() +}) + +// db.run("CREATE DATABASE massive;", function (err, res) { +// if(err) { +// throw (new Error(err.message)) +// } +// console.log(res) +// process.exit() +// }) From 4b9a5c915faa32bb706d84fe433009b03939357d Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 15:46:17 -0700 Subject: [PATCH 09/79] Updated package.json; scripts + seed to db:reset (not yet working) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd18c6d29..674ee1d7d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "db:create": "createdb massive", "db:seed": "clear; node tasks/db_seed.js", "db:drop": "dropdb massive", - "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", "db:schema": "clear; node tasks/load_schema.js" }, "dependencies": { From 44cf9d11cd0e15adc5600a71dadb819cdfd0882e Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:05:59 -0700 Subject: [PATCH 10/79] Added instance of controller to customers routes --- routes/customers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/customers.js b/routes/customers.js index 4c3397ddd..0b547cc9d 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -1,5 +1,6 @@ var express = require('express') var router = express.Router() +var Controller = require('../controllers/customers') /* GET home page. */ router.get('/sort/', function (req, res, next) { From 80cc37830a09c3c0192cd4e7695a0ea168109c84 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:06:15 -0700 Subject: [PATCH 11/79] Added instance of movies to movies routes --- routes/movies.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/movies.js b/routes/movies.js index 06cfc1137..64b0deee4 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -1,5 +1,6 @@ var express = require('express'); var router = express.Router(); +var Controller = require('../controllers/movies') /* GET home page. */ router.get('/', function(req, res, next) { From 92c4acfe2a3f23439b8c2befc147889a9cb30017 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:06:33 -0700 Subject: [PATCH 12/79] extra index routes --- routes/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/index.js b/routes/index.js index c0b19478f..51c5c6268 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,6 +1,7 @@ var express = require('express'); var router = express.Router(); + /* GET home page. */ router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) From c13105cfeafcbf16a8203156aa678a8aa583a622 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:06:51 -0700 Subject: [PATCH 13/79] fixed scripts, seed still bad --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 674ee1d7d..a16174835 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:create": "createdb massive", + "db:create": "createdb customers; createdb movies; createdb rentals", "db:seed": "clear; node tasks/db_seed.js", - "db:drop": "dropdb massive", + "db:drop": "dropdb customers; dropdb movies; dropdb rentals", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", "db:schema": "clear; node tasks/load_schema.js" }, From 82528b91cdca5ac6d20f8b601b42228f3934523f Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:20:32 -0700 Subject: [PATCH 14/79] Idunnolol --- routes/controllers/customers.js | 23 +++++++++++++++++++++++ routes/controllers/movies.js | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 routes/controllers/customers.js create mode 100644 routes/controllers/movies.js diff --git a/routes/controllers/customers.js b/routes/controllers/customers.js new file mode 100644 index 000000000..625e85c3f --- /dev/null +++ b/routes/controllers/customers.js @@ -0,0 +1,23 @@ +var CustomerController = { +// index: function (req, res, next) { +// res.render('index', { title: 'Express' }) +// }, +// +// doSomething: function (request, response) { +// var locals = {} +// locals.title = 'RANDOM PARTY GENERATOR' +// // pick rand number between 1-100 +// locals.attendees = Math.floor(Math.random() * 100 + 1) +// // pick random day of week +// function sample (array) { +// return array[Math.floor(Math.random() * array.length)] +// } +// +// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) +// // pick a costume theme for your party +// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) +// response.render('party', locals) +// } +// } + +module.exports = CustomerController diff --git a/routes/controllers/movies.js b/routes/controllers/movies.js new file mode 100644 index 000000000..b940274a0 --- /dev/null +++ b/routes/controllers/movies.js @@ -0,0 +1,23 @@ +var MovieController = { + // index: function (req, res, next) { + // res.render('index', { title: 'Express' }) + // }, + +// getParty: function (request, response) { +// var locals = {} +// locals.title = 'RANDOM PARTY GENERATOR' +// // pick rand number between 1-100 +// locals.attendees = Math.floor(Math.random() * 100 + 1) +// // pick random day of week +// function sample (array) { +// return array[Math.floor(Math.random() * array.length)] +// } +// +// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) +// // pick a costume theme for your party +// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) +// response.render('party', locals) +// } +// } + +module.exports = MovieController From d064cb3c1c752af74a91ae97d8348e8925f9a7b2 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:21:21 -0700 Subject: [PATCH 15/79] Controller scaffolding, no complete methods --- controllers/customers.js | 53 ++++++++++++++++++++++++++++++++++++++++ controllers/movies.js | 23 +++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 controllers/customers.js create mode 100644 controllers/movies.js diff --git a/controllers/customers.js b/controllers/customers.js new file mode 100644 index 000000000..26bab979e --- /dev/null +++ b/controllers/customers.js @@ -0,0 +1,53 @@ +var CustomerController = { + sortName: function (req, res, next) { + res.send( + // CODE TO RETRIEVE CUSTOMERS BY NAME HERE + )} + } + + sortDate: function (req, res, next) { + res.send( + // CODE TO RETRIEVE CUSTOMERS BY registered_at + )} + } + + sortPostalCode: function (req, res, next) { + res.send( + // CODE TO RETRIEVE CUSTOMERS BY postal_code + )} + } + + current: function (req, res, next) { + res.send( + // CODE TO RETRIEVE currently checked out rentals by customer + )} + } + + history: function (req, res, next) { + res.send( + // CODE TO RETRIEVE previously checked out rentals by customer + )} + } + +// index: function (req, res, next) { +// res.render('index', { title: 'Express' }) +// }, +// +// doSomething: function (request, response) { +// var locals = {} +// locals.title = 'RANDOM PARTY GENERATOR' +// // pick rand number between 1-100 +// locals.attendees = Math.floor(Math.random() * 100 + 1) +// // pick random day of week +// function sample (array) { +// return array[Math.floor(Math.random() * array.length)] +// } +// +// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) +// // pick a costume theme for your party +// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) +// response.render('party', locals) +// } +// } + +module.exports = CustomerController diff --git a/controllers/movies.js b/controllers/movies.js new file mode 100644 index 000000000..b940274a0 --- /dev/null +++ b/controllers/movies.js @@ -0,0 +1,23 @@ +var MovieController = { + // index: function (req, res, next) { + // res.render('index', { title: 'Express' }) + // }, + +// getParty: function (request, response) { +// var locals = {} +// locals.title = 'RANDOM PARTY GENERATOR' +// // pick rand number between 1-100 +// locals.attendees = Math.floor(Math.random() * 100 + 1) +// // pick random day of week +// function sample (array) { +// return array[Math.floor(Math.random() * array.length)] +// } +// +// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) +// // pick a costume theme for your party +// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) +// response.render('party', locals) +// } +// } + +module.exports = MovieController From 9e4f4628f81c7bc5e5cc7012fed1361a58e9d1b2 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:21:48 -0700 Subject: [PATCH 16/79] Customers routes updated --- routes/controllers/customers.js | 23 ----------------------- routes/controllers/movies.js | 23 ----------------------- routes/customers.js | 9 ++++++--- 3 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 routes/controllers/customers.js delete mode 100644 routes/controllers/movies.js diff --git a/routes/controllers/customers.js b/routes/controllers/customers.js deleted file mode 100644 index 625e85c3f..000000000 --- a/routes/controllers/customers.js +++ /dev/null @@ -1,23 +0,0 @@ -var CustomerController = { -// index: function (req, res, next) { -// res.render('index', { title: 'Express' }) -// }, -// -// doSomething: function (request, response) { -// var locals = {} -// locals.title = 'RANDOM PARTY GENERATOR' -// // pick rand number between 1-100 -// locals.attendees = Math.floor(Math.random() * 100 + 1) -// // pick random day of week -// function sample (array) { -// return array[Math.floor(Math.random() * array.length)] -// } -// -// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) -// // pick a costume theme for your party -// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) -// response.render('party', locals) -// } -// } - -module.exports = CustomerController diff --git a/routes/controllers/movies.js b/routes/controllers/movies.js deleted file mode 100644 index b940274a0..000000000 --- a/routes/controllers/movies.js +++ /dev/null @@ -1,23 +0,0 @@ -var MovieController = { - // index: function (req, res, next) { - // res.render('index', { title: 'Express' }) - // }, - -// getParty: function (request, response) { -// var locals = {} -// locals.title = 'RANDOM PARTY GENERATOR' -// // pick rand number between 1-100 -// locals.attendees = Math.floor(Math.random() * 100 + 1) -// // pick random day of week -// function sample (array) { -// return array[Math.floor(Math.random() * array.length)] -// } -// -// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) -// // pick a costume theme for your party -// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) -// response.render('party', locals) -// } -// } - -module.exports = MovieController diff --git a/routes/customers.js b/routes/customers.js index 0b547cc9d..789460454 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -3,8 +3,11 @@ var router = express.Router() var Controller = require('../controllers/customers') /* GET home page. */ -router.get('/sort/', function (req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) -}) +router.get('/sort/name', Controller.sortName) +router.get('/sort/registered-at', Controller.sortDate) +router.get('/sort/postal-code', Controller.sortPostalCode) + +router.get('/:id/current', Controller.current) +router.get('/:id/history', Controller.history) module.exports = router From 43342762d70deb7c0d603958128e5ddceea40171 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:22:15 -0700 Subject: [PATCH 17/79] task to seed - INCORRECT --- tasks/db_seed.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/db_seed.js b/tasks/db_seed.js index f752e140e..c0a78a5df 100644 --- a/tasks/db_seed.js +++ b/tasks/db_seed.js @@ -5,7 +5,7 @@ var movieSeed = require('../db/seeds/movies') var db = massive.connectSync({connectionString: connectionString}) -db.seed.customers([customerSeed], function (err, res) { +db.seed.customers(customerSeed, function (err, res) { if (err) { throw (new Error(err.message)) } @@ -14,7 +14,7 @@ db.seed.customers([customerSeed], function (err, res) { process.exit() }) -db.seed.movies([movieSeed], function (err, res) { +db.seed.movies(movieSeed, function (err, res) { if (err) { throw (new Error(err.message)) } From aeaad3c7aa5043e2106d8d9587470d9f7efe51dd Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:27:20 -0700 Subject: [PATCH 18/79] movies routes to controller, includes rentals --- routes/movies.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/routes/movies.js b/routes/movies.js index 64b0deee4..d0f45b5f9 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -1,10 +1,17 @@ -var express = require('express'); -var router = express.Router(); +var express = require('express') +var router = express.Router() var Controller = require('../controllers/movies') /* GET home page. */ -router.get('/', function(req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) -}); +router.get('/sort/title', Controller.sortTitle) +router.get('/sort/release', Controller.sortRelease) +router.get('/:title/current', Controller.current) +router.get('/:title/history', Controller.history) + +router.get('/rentals/:title', Controller.rentalsTitle) +router.get('/rentals/:title/customers', Controller.rentalsCustomers) +router.post('/rentals/:title/checkout', Controller.checkout) +router.patch('/rentals/:title/return', Controller.return) +router.get('/rentals/overdue', Controller.overdue) module.exports = router; From 8b82b5601d06ec7b6eb089c8c27659ac20f89bd9 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:33:35 -0700 Subject: [PATCH 19/79] not sure what you want me to commit, git --- routes/controllers/movies.js | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 routes/controllers/movies.js diff --git a/routes/controllers/movies.js b/routes/controllers/movies.js new file mode 100644 index 000000000..0f0967959 --- /dev/null +++ b/routes/controllers/movies.js @@ -0,0 +1,56 @@ +var MovieController = { + sortTitle: function (req, res, next) { + res.send( + // CODE TO RETRIEVE movies, sorted by title + )} + } + + sortRelease: function (req, res, next) { + res.send( + // CODE TO RETRIEVE movies, sorted by release date + )} + } + + current: function (req, res, next) { + res.send( + // CODE TO RETRIEVE rentals that are (currently checked out) by title + )} + } + + history: function (req, res, next) { + res.send( + // CODE TO RETRIEVE rentals that were previously checked out by title + )} + } + + rentalsTitle: function (req, res, next) { + res.send( + // HOW IS THIS DIFFERENT FROM CURRENT/HISTORY BY TITLE? + )} + } + + rentalsCustomers: function (req, res, next) { + res.send( + // + )} + } + + checkout: function (req, res, next) { + res.send( + // + )} + } + + return: function (req, res, next) { + res.send( + // + )} + } + + overdue: function (req, res, next) { + res.send( + // + )} + } + +module.exports = MovieController From ea9ab9b860ffc0e678cf037697478e5267b99deb Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 14 Jun 2016 16:33:58 -0700 Subject: [PATCH 20/79] log stuff that probably goes in the .gitignore --- npm-debug.log | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 000000000..3beaa2392 --- /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:seed' ] +2 info using npm@3.9.3 +3 info using node@v6.2.1 +4 verbose run-script [ 'predb:seed', 'db:seed', 'postdb:seed' ] +5 info lifecycle video-store-api@0.0.0~predb:seed: video-store-api@0.0.0 +6 silly lifecycle video-store-api@0.0.0~predb:seed: no script for predb:seed, continuing +7 info lifecycle video-store-api@0.0.0~db:seed: video-store-api@0.0.0 +8 verbose lifecycle video-store-api@0.0.0~db:seed: unsafe-perm in lifecycle true +9 verbose lifecycle video-store-api@0.0.0~db:seed: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/nicosaki/Dropbox/Ada/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/nicosaki/.rvm/gems/ruby-2.3.0/bin:/Users/nicosaki/.rvm/gems/ruby-2.3.0@global/bin:/Users/nicosaki/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/nicosaki/.rvm/bin:/Users/nicosaki/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~db:seed: CWD: /Users/nicosaki/Dropbox/Ada/C5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~db:seed: Args: [ '-c', 'clear; node tasks/db_seed.js' ] +12 silly lifecycle video-store-api@0.0.0~db:seed: Returned: code: 1 signal: null +13 info lifecycle video-store-api@0.0.0~db:seed: Failed to exec db:seed script +14 verbose stack Error: video-store-api@0.0.0 db:seed: `clear; node tasks/db_seed.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/nicosaki/Dropbox/Ada/C5/projects/VideoStoreAPI +17 error Darwin 15.3.0 +18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "db:seed" +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:seed: `clear; node tasks/db_seed.js` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 db:seed script 'clear; node tasks/db_seed.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 clear; node tasks/db_seed.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 ] From 740a6802daf9c9ec14021db53f5d5e0e058bac2d Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Wed, 15 Jun 2016 09:15:22 -0700 Subject: [PATCH 21/79] moved controllers to correct file, deleted extra movies controller --- controllers/movies.js | 73 ++++++++++++++++++++++++++---------- routes/controllers/movies.js | 56 --------------------------- 2 files changed, 53 insertions(+), 76 deletions(-) delete mode 100644 routes/controllers/movies.js diff --git a/controllers/movies.js b/controllers/movies.js index b940274a0..0f0967959 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -1,23 +1,56 @@ var MovieController = { - // index: function (req, res, next) { - // res.render('index', { title: 'Express' }) - // }, - -// getParty: function (request, response) { -// var locals = {} -// locals.title = 'RANDOM PARTY GENERATOR' -// // pick rand number between 1-100 -// locals.attendees = Math.floor(Math.random() * 100 + 1) -// // pick random day of week -// function sample (array) { -// return array[Math.floor(Math.random() * array.length)] -// } -// -// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) -// // pick a costume theme for your party -// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) -// response.render('party', locals) -// } -// } + sortTitle: function (req, res, next) { + res.send( + // CODE TO RETRIEVE movies, sorted by title + )} + } + + sortRelease: function (req, res, next) { + res.send( + // CODE TO RETRIEVE movies, sorted by release date + )} + } + + current: function (req, res, next) { + res.send( + // CODE TO RETRIEVE rentals that are (currently checked out) by title + )} + } + + history: function (req, res, next) { + res.send( + // CODE TO RETRIEVE rentals that were previously checked out by title + )} + } + + rentalsTitle: function (req, res, next) { + res.send( + // HOW IS THIS DIFFERENT FROM CURRENT/HISTORY BY TITLE? + )} + } + + rentalsCustomers: function (req, res, next) { + res.send( + // + )} + } + + checkout: function (req, res, next) { + res.send( + // + )} + } + + return: function (req, res, next) { + res.send( + // + )} + } + + overdue: function (req, res, next) { + res.send( + // + )} + } module.exports = MovieController diff --git a/routes/controllers/movies.js b/routes/controllers/movies.js deleted file mode 100644 index 0f0967959..000000000 --- a/routes/controllers/movies.js +++ /dev/null @@ -1,56 +0,0 @@ -var MovieController = { - sortTitle: function (req, res, next) { - res.send( - // CODE TO RETRIEVE movies, sorted by title - )} - } - - sortRelease: function (req, res, next) { - res.send( - // CODE TO RETRIEVE movies, sorted by release date - )} - } - - current: function (req, res, next) { - res.send( - // CODE TO RETRIEVE rentals that are (currently checked out) by title - )} - } - - history: function (req, res, next) { - res.send( - // CODE TO RETRIEVE rentals that were previously checked out by title - )} - } - - rentalsTitle: function (req, res, next) { - res.send( - // HOW IS THIS DIFFERENT FROM CURRENT/HISTORY BY TITLE? - )} - } - - rentalsCustomers: function (req, res, next) { - res.send( - // - )} - } - - checkout: function (req, res, next) { - res.send( - // - )} - } - - return: function (req, res, next) { - res.send( - // - )} - } - - overdue: function (req, res, next) { - res.send( - // - )} - } - -module.exports = MovieController From d9674539d4032cbcd07aaad0d91cc426de210be0 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Wed, 15 Jun 2016 14:07:35 -0700 Subject: [PATCH 22/79] updated seed script, unknown if works --- tasks/db_seed.js | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/tasks/db_seed.js b/tasks/db_seed.js index c0a78a5df..12b1a32ee 100644 --- a/tasks/db_seed.js +++ b/tasks/db_seed.js @@ -5,20 +5,34 @@ var movieSeed = require('../db/seeds/movies') var db = massive.connectSync({connectionString: connectionString}) -db.seed.customers(customerSeed, function (err, res) { - if (err) { - throw (new Error(err.message)) - } +for (var record of movieSeed) { + console.log(record.title, record.release_date) + db.movies.saveSync(record) +} - console.log('schema!') - process.exit() -}) +process.exit() -db.seed.movies(movieSeed, function (err, res) { - if (err) { - throw (new Error(err.message)) - } +for (var record of customerSeed) { + console.log(record.name, record.address) + db.customers.saveSync(record) +} - console.log('schema!') - process.exit() -}) +process.exit() +// +// db.seed.customers(customerSeed, function (err, res) { +// if (err) { +// throw (new Error(err.message)) +// } +// +// console.log('schema!') +// process.exit() +// }) +// +// db.seed.movies(movieSeed, function (err, res) { +// if (err) { +// throw (new Error(err.message)) +// } +// +// console.log('schema!') +// process.exit() +// }) From d0f5940510fd4b5ef1f670bf91dfcbb3b0d92481 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Wed, 15 Jun 2016 14:39:21 -0700 Subject: [PATCH 23/79] finished seed script with asynch functionality --- controllers/customers.js | 67 +++++++++++++--------------------------- tasks/db_seed.js | 62 +++++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 69 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 26bab979e..2ea75ea33 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -1,53 +1,28 @@ var CustomerController = { - sortName: function (req, res, next) { - res.send( - // CODE TO RETRIEVE CUSTOMERS BY NAME HERE - )} - } + sortName: function (req, res, next) { + res.send( + // CODE TO RETRIEVE CUSTOMERS BY NAME HERE + ) }, - sortDate: function (req, res, next) { - res.send( - // CODE TO RETRIEVE CUSTOMERS BY registered_at - )} - } + sortDate: function (req, res, next) { + res.send( + // CODE TO RETRIEVE CUSTOMERS BY registered_at + ) }, - sortPostalCode: function (req, res, next) { - res.send( - // CODE TO RETRIEVE CUSTOMERS BY postal_code - )} - } + sortPostalCode: function (req, res, next) { + res.send( + // CODE TO RETRIEVE CUSTOMERS BY postal_code + ) }, - current: function (req, res, next) { - res.send( - // CODE TO RETRIEVE currently checked out rentals by customer - )} - } + current: function (req, res, next) { + res.send( + // CODE TO RETRIEVE currently checked out rentals by customer + ) }, - history: function (req, res, next) { - res.send( - // CODE TO RETRIEVE previously checked out rentals by customer - )} - } - -// index: function (req, res, next) { -// res.render('index', { title: 'Express' }) -// }, -// -// doSomething: function (request, response) { -// var locals = {} -// locals.title = 'RANDOM PARTY GENERATOR' -// // pick rand number between 1-100 -// locals.attendees = Math.floor(Math.random() * 100 + 1) -// // pick random day of week -// function sample (array) { -// return array[Math.floor(Math.random() * array.length)] -// } -// -// locals.day = sample(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']) -// // pick a costume theme for your party -// locals.theme = sample(['Toga', 'Halloween', 'Black Light', 'Jungle', 'Neon']) -// response.render('party', locals) -// } -// } + history: function (req, res, next) { + res.send( + // CODE TO RETRIEVE previously checked out rentals by customer + ) } +} module.exports = CustomerController diff --git a/tasks/db_seed.js b/tasks/db_seed.js index 12b1a32ee..d2a1f7057 100644 --- a/tasks/db_seed.js +++ b/tasks/db_seed.js @@ -4,35 +4,51 @@ var customerSeed = require('../db/seeds/customers') var movieSeed = require('../db/seeds/movies') var db = massive.connectSync({connectionString: connectionString}) +var movieRecords = movieSeed.length +var customerRecords = movieSeed.length for (var record of movieSeed) { - console.log(record.title, record.release_date) - db.movies.saveSync(record) + db.movies.save(record, function (err, res) { + if (err) { + throw (new Error(err.message)) + } + console.log('saved: ', JSON.stringify(res)) + db.movies.count(function (err, res) { + if (err) { + throw (new Error(err.message)) + } + console.log('records in db: ', res) + if (res >= movieRecords) { process.exit() } + }) + }) } -process.exit() - for (var record of customerSeed) { - console.log(record.name, record.address) - db.customers.saveSync(record) + db.customers.save(record, function (err, res) { + if (err) { + throw (new Error(err.message)) + } + console.log('saved: ', JSON.stringify(res)) + db.customers.count(function (err, res) { + if (err) { + throw (new Error(err.message)) + } + console.log('records in db: ', res) + if (res >= customerRecords) { process.exit() } + }) + }) } - -process.exit() -// -// db.seed.customers(customerSeed, function (err, res) { -// if (err) { -// throw (new Error(err.message)) -// } +// ========================================================= +// for (var record of movieSeed) { +// console.log(record.title, record.release_date) +// db.movies.saveSync(record) +// } // -// console.log('schema!') -// process.exit() -// }) +// process.exit() // -// db.seed.movies(movieSeed, function (err, res) { -// if (err) { -// throw (new Error(err.message)) -// } +// for (var record of customerSeed) { +// console.log(record.name, record.address) +// db.customers.saveSync(record) +// } // -// console.log('schema!') -// process.exit() -// }) +// process.exit() From e1b1b147d0e4a845023d1d846cff315b8dd233b2 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Wed, 15 Jun 2016 15:05:42 -0700 Subject: [PATCH 24/79] fixed schema - still no index but is working --- db/setup/schema.sql | 2 +- npm-debug.log | 48 --------------------------------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 npm-debug.log diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 47d1fd59b..1b8153a33 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -7,7 +7,7 @@ CREATE TABLE customers( state text, postal_code text, phone text, - account_credit integer, + account_credit float, registered_at date ); diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 3beaa2392..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:seed' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'predb:seed', 'db:seed', 'postdb:seed' ] -5 info lifecycle video-store-api@0.0.0~predb:seed: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~predb:seed: no script for predb:seed, continuing -7 info lifecycle video-store-api@0.0.0~db:seed: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~db:seed: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~db:seed: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/nicosaki/Dropbox/Ada/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/nicosaki/.rvm/gems/ruby-2.3.0/bin:/Users/nicosaki/.rvm/gems/ruby-2.3.0@global/bin:/Users/nicosaki/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/nicosaki/.rvm/bin:/Users/nicosaki/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~db:seed: CWD: /Users/nicosaki/Dropbox/Ada/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~db:seed: Args: [ '-c', 'clear; node tasks/db_seed.js' ] -12 silly lifecycle video-store-api@0.0.0~db:seed: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~db:seed: Failed to exec db:seed script -14 verbose stack Error: video-store-api@0.0.0 db:seed: `clear; node tasks/db_seed.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/nicosaki/Dropbox/Ada/C5/projects/VideoStoreAPI -17 error Darwin 15.3.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "db:seed" -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:seed: `clear; node tasks/db_seed.js` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 db:seed script 'clear; node tasks/db_seed.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 clear; node tasks/db_seed.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 ] From e0bfbbcf5190637dc3a542f0bf3a111ffaf5ee52 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Wed, 15 Jun 2016 15:31:37 -0700 Subject: [PATCH 25/79] fixed massive db errors --- package.json | 4 ++-- tasks/load_schema.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a16174835..4970866e1 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:create": "createdb customers; createdb movies; createdb rentals", + "db:create": "createdb video_store", "db:seed": "clear; node tasks/db_seed.js", - "db:drop": "dropdb customers; dropdb movies; dropdb rentals", + "db:drop": "dropdb video_store", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", "db:schema": "clear; node tasks/load_schema.js" }, diff --git a/tasks/load_schema.js b/tasks/load_schema.js index 7735e86e8..ca1c99ddf 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = 'postgres://localhost/massive' +var connectionString = 'postgres://localhost/video_store' var db = massive.connectSync({connectionString: connectionString}) From 273fb946699b4ebe067179fcb493faf87570f141 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Wed, 15 Jun 2016 15:35:23 -0700 Subject: [PATCH 26/79] edited an error where massive was being referred to as a database. changed to video_store. --- app.js | 3 +++ db/setup/schema.sql | 9 ++++++--- package.json | 4 ++-- tasks/db_seed.js | 2 +- tasks/load_schema.js | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 463460ff1..5f4d24ed2 100644 --- a/app.js +++ b/app.js @@ -8,6 +8,9 @@ var bodyParser = require('body-parser'); var routes = require('./routes/index'); var app = express(); +var massive = require("massive") +var connectionString = "postgres://localhost/video_store" + // divide responsibilities. everything in "movies" will have /movies in its url. var movies = require('./routes/movies'); app.use('/movies', movies) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 1b8153a33..34dbb39ab 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -11,7 +11,8 @@ CREATE TABLE customers( registered_at date ); --- CREATE INDEX words_word ON words (word); FIX THIS, I HAVE NO IDEA WHAT INDEX +CREATE INDEX customers_name ON customers (name); + -- FIX THIS, I HAVE NO IDEA WHAT INDEX DROP TABLE IF EXISTS movies; CREATE TABLE movies( @@ -23,7 +24,8 @@ CREATE TABLE movies( release_date date ); --- CREATE INDEX words_word ON words (word); FIX THIS, I HAVE NO IDEA WHAT INDEX +CREATE INDEX movies_title ON movies (title); +-- FIX THIS, I HAVE NO IDEA WHAT INDEX DROP TABLE IF EXISTS rentals; CREATE TABLE rentals( @@ -35,4 +37,5 @@ CREATE TABLE rentals( due_date date ); --- CREATE INDEX words_word ON words (word); FIX THIS, I HAVE NO IDEA WHAT INDEX +CREATE INDEX rentals_movie_id ON rentals (movie_id); +-- FIX THIS, I HAVE NO IDEA WHAT INDEX diff --git a/package.json b/package.json index a16174835..4970866e1 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:create": "createdb customers; createdb movies; createdb rentals", + "db:create": "createdb video_store", "db:seed": "clear; node tasks/db_seed.js", - "db:drop": "dropdb customers; dropdb movies; dropdb rentals", + "db:drop": "dropdb video_store", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", "db:schema": "clear; node tasks/load_schema.js" }, diff --git a/tasks/db_seed.js b/tasks/db_seed.js index d2a1f7057..d2a922e30 100644 --- a/tasks/db_seed.js +++ b/tasks/db_seed.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = 'postgres://localhost/massive' +var connectionString = 'postgres://localhost/video_store' var customerSeed = require('../db/seeds/customers') var movieSeed = require('../db/seeds/movies') diff --git a/tasks/load_schema.js b/tasks/load_schema.js index 7735e86e8..ca1c99ddf 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = 'postgres://localhost/massive' +var connectionString = 'postgres://localhost/video_store' var db = massive.connectSync({connectionString: connectionString}) From 3399dab4758c482eeb54b96bcc690eb50066c2cd Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Wed, 15 Jun 2016 15:36:54 -0700 Subject: [PATCH 27/79] fixed seed script --- tasks/db_seed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/db_seed.js b/tasks/db_seed.js index d2a1f7057..d2a922e30 100644 --- a/tasks/db_seed.js +++ b/tasks/db_seed.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = 'postgres://localhost/massive' +var connectionString = 'postgres://localhost/video_store' var customerSeed = require('../db/seeds/customers') var movieSeed = require('../db/seeds/movies') From 0d437a23d10510ebbd0384fcdd90623dc7ae044b Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 09:00:46 -0700 Subject: [PATCH 28/79] two SQL commands for movies controller --- controllers/movies.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/controllers/movies.js b/controllers/movies.js index 0f0967959..a94068f02 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -2,11 +2,13 @@ var MovieController = { sortTitle: function (req, res, next) { res.send( // CODE TO RETRIEVE movies, sorted by title + SELECT * FROM movies ORDER BY title; )} } sortRelease: function (req, res, next) { res.send( + SELECT * FROM movies ORDER BY release_date; // CODE TO RETRIEVE movies, sorted by release date )} } @@ -49,7 +51,7 @@ var MovieController = { overdue: function (req, res, next) { res.send( - // + // )} } From f1003220ab082621576d9edc0b2621238a37a82a Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 14:11:41 -0700 Subject: [PATCH 29/79] sorttitle controller function returns JSON of sorted movie titles --- controllers/movies.js | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index a94068f02..3b77af8d1 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -1,58 +1,58 @@ +var Massive = require("massive"); +var db = Massive.connectSync({db : "video_store"}); + var MovieController = { sortTitle: function (req, res, next) { - res.send( - // CODE TO RETRIEVE movies, sorted by title - SELECT * FROM movies ORDER BY title; - )} - } + + db.query("select * from movies order by title", function(err, movies){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(movies) + } + }); + }, sortRelease: function (req, res, next) { res.send( - SELECT * FROM movies ORDER BY release_date; + // SELECT * FROM movies ORDER BY release_date; // CODE TO RETRIEVE movies, sorted by release date - )} - } + )}, current: function (req, res, next) { res.send( // CODE TO RETRIEVE rentals that are (currently checked out) by title - )} - } + )}, history: function (req, res, next) { res.send( // CODE TO RETRIEVE rentals that were previously checked out by title - )} - } + )}, rentalsTitle: function (req, res, next) { res.send( // HOW IS THIS DIFFERENT FROM CURRENT/HISTORY BY TITLE? - )} - } + )}, rentalsCustomers: function (req, res, next) { res.send( // - )} - } + )}, checkout: function (req, res, next) { res.send( // - )} - } + )}, return: function (req, res, next) { res.send( // - )} - } + )}, overdue: function (req, res, next) { res.send( // )} - } - +} module.exports = MovieController From ea0a92837f852b079638deaf23bd84a65be2be85 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 14:14:05 -0700 Subject: [PATCH 30/79] movies sortrelease works --- controllers/movies.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 3b77af8d1..cb5645727 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -15,10 +15,15 @@ var MovieController = { }, sortRelease: function (req, res, next) { - res.send( - // SELECT * FROM movies ORDER BY release_date; - // CODE TO RETRIEVE movies, sorted by release date - )}, + db.query("select * from movies order by release_date", function(err, movies){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(movies) + } + }); + }, current: function (req, res, next) { res.send( From b25414115fdff5ec919ac5c972dfc93dad1fc789 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 14:22:33 -0700 Subject: [PATCH 31/79] created rentals seed --- db/seeds/rentals.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 db/seeds/rentals.json diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json new file mode 100644 index 000000000..2d5829448 --- /dev/null +++ b/db/seeds/rentals.json @@ -0,0 +1,23 @@ +[ +{ +"customer_id": 1, +"movie_id": 2, +"check_out_date": "2016-06-14", +"checked_out": true, +"due_date": "2016-06-24" +}, +{ +"customer_id": 2, +"movie_id": 4, +"check_out_date": "2015-02-14", +"checked_out": true, +"due_date": "2015-02-24" +}, +{ +"customer_id": 2, +"movie_id": 7, +"check_out_date": "2013-06-15", +"checked_out": false, +"due_date": "2013-06-30" +} +] From 730fd1cfc9212ab51a17f657388c21e343326eeb Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Thu, 16 Jun 2016 14:24:47 -0700 Subject: [PATCH 32/79] Added rental seed script --- tasks/db_seed.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tasks/db_seed.js b/tasks/db_seed.js index d2a922e30..41418cc57 100644 --- a/tasks/db_seed.js +++ b/tasks/db_seed.js @@ -2,10 +2,12 @@ var massive = require('massive') var connectionString = 'postgres://localhost/video_store' var customerSeed = require('../db/seeds/customers') var movieSeed = require('../db/seeds/movies') +var rentalSeed = require('../db/seeds/rentals') var db = massive.connectSync({connectionString: connectionString}) var movieRecords = movieSeed.length var customerRecords = movieSeed.length +var rentalRecords = rentalSeed.length for (var record of movieSeed) { db.movies.save(record, function (err, res) { @@ -38,6 +40,22 @@ for (var record of customerSeed) { }) }) } + +for (var record of rentalSeed) { + db.rentals.save(record, function (err, res) { + if (err) { + throw (new Error(err.message)) + } + console.log('saved: ', JSON.stringify(res)) + db.rentals.count(function (err, res) { + if (err) { + throw (new Error(err.message)) + } + console.log('records in db: ', res) + if (res >= rentalRecords) { process.exit() } + }) + }) +} // ========================================================= // for (var record of movieSeed) { // console.log(record.title, record.release_date) From 28c1ac3ca9ec1fa86d098cdb8b74b4fa5890eb62 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Thu, 16 Jun 2016 14:50:42 -0700 Subject: [PATCH 33/79] Ability to see currently checked out movies by id number --- controllers/movies.js | 23 ++++++++++++++++------- routes/movies.js | 12 ++++++------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index cb5645727..879326a1a 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -4,31 +4,40 @@ var db = Massive.connectSync({db : "video_store"}); var MovieController = { sortTitle: function (req, res, next) { - db.query("select * from movies order by title", function(err, movies){ + db.query("select * from movies order by title", function(err, movieRecords){ if(err) { var err = new Error("It's an error") next(err) } else { - res.json(movies) + res.json(movieRecords) } }); }, sortRelease: function (req, res, next) { - db.query("select * from movies order by release_date", function(err, movies){ + db.query("select * from movies order by release_date", function(err, movieRecords){ if(err) { var err = new Error("It's an error") next(err) } else { - res.json(movies) + res.json(movieRecords) } }); }, current: function (req, res, next) { - res.send( - // CODE TO RETRIEVE rentals that are (currently checked out) by title - )}, + var movie_id = req.params.id + console.log(movie_id) + console.log(req.params) + db.query("select * from rentals where checked_out = true and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(movieRecords) + } + }); + }, history: function (req, res, next) { res.send( diff --git a/routes/movies.js b/routes/movies.js index d0f45b5f9..4ea95002e 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -6,12 +6,12 @@ var Controller = require('../controllers/movies') router.get('/sort/title', Controller.sortTitle) router.get('/sort/release', Controller.sortRelease) -router.get('/:title/current', Controller.current) -router.get('/:title/history', Controller.history) +router.get('/:id/current', Controller.current) +router.get('/:id/history', Controller.history) -router.get('/rentals/:title', Controller.rentalsTitle) -router.get('/rentals/:title/customers', Controller.rentalsCustomers) -router.post('/rentals/:title/checkout', Controller.checkout) -router.patch('/rentals/:title/return', Controller.return) +router.get('/rentals/:id', Controller.rentalsTitle) +router.get('/rentals/:id/customers', Controller.rentalsCustomers) +router.post('/rentals/:id/checkout', Controller.checkout) +router.patch('/rentals/:id/return', Controller.return) router.get('/rentals/overdue', Controller.overdue) module.exports = router; From b1a410f7465f0e4c5a3b0b2ccdc48b2caaec56c3 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Thu, 16 Jun 2016 14:51:44 -0700 Subject: [PATCH 34/79] Ability to see previously checked out movies by id number --- controllers/movies.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 879326a1a..2533b4765 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -40,9 +40,18 @@ var MovieController = { }, history: function (req, res, next) { - res.send( - // CODE TO RETRIEVE rentals that were previously checked out by title - )}, + var movie_id = req.params.id + console.log(movie_id) + console.log(req.params) + db.query("select * from rentals where checked_out = false and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(movieRecords) + } + }); + }, rentalsTitle: function (req, res, next) { res.send( From 0abe12d8d910547342f8ca034e9cf9089f2f521e Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 15:03:46 -0700 Subject: [PATCH 35/79] added rentals to app.js routes --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index 5f4d24ed2..b38989cb9 100644 --- a/app.js +++ b/app.js @@ -18,6 +18,9 @@ app.use('/movies', movies) var customers = require('./routes/customers'); app.use('/customers', customers) +var rentals = require('./routes/rentals'); +app.use('/rentals', rentals) + // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); From 444e42a0fb7a4bf2631cf507fd6ac116c0b16760 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 15:10:42 -0700 Subject: [PATCH 36/79] no rentals routes nevermind hehe --- app.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app.js b/app.js index b38989cb9..5f4d24ed2 100644 --- a/app.js +++ b/app.js @@ -18,9 +18,6 @@ app.use('/movies', movies) var customers = require('./routes/customers'); app.use('/customers', customers) -var rentals = require('./routes/rentals'); -app.use('/rentals', rentals) - // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); From 8b5b2227923dff422e487c364c7add78f56c0fd8 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Thu, 16 Jun 2016 15:31:38 -0700 Subject: [PATCH 37/79] Added all movies endpoints and rentalsTitle(NONFUNCTIONAL) to movies controller --- controllers/movies.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 2533b4765..0bda6b860 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -27,8 +27,6 @@ var MovieController = { current: function (req, res, next) { var movie_id = req.params.id - console.log(movie_id) - console.log(req.params) db.query("select * from rentals where checked_out = true and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ if(err) { var err = new Error("It's an error") @@ -41,8 +39,6 @@ var MovieController = { history: function (req, res, next) { var movie_id = req.params.id - console.log(movie_id) - console.log(req.params) db.query("select * from rentals where checked_out = false and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ if(err) { var err = new Error("It's an error") @@ -54,9 +50,24 @@ var MovieController = { }, rentalsTitle: function (req, res, next) { - res.send( - // HOW IS THIS DIFFERENT FROM CURRENT/HISTORY BY TITLE? - )}, + var movie_id = req.params.id + db.query("select * from rentals where movie_id = $1 and checked_out = true"), [movie_id], function(err, rentalRecords) { + if(err) { + throw (new Error(err.message)) + } else { + db.query("select * from movies where movie_id=$1 asc", [movie_id], function(err, movieRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + var available = movieRecords.inventory - rentalRecords.length + res.json({movieRecords: movieRecords, available: available}) + } + }); + } + } +}, +// NOT YET COMPLETE/FUNCTIONAL rentalsCustomers: function (req, res, next) { res.send( From f8acce5120e351260bb60ed3af79aa89243be896 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 15:47:24 -0700 Subject: [PATCH 38/79] added customer id to movie routes that check in and check out movies --- routes/movies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/movies.js b/routes/movies.js index 4ea95002e..68fccf253 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -11,7 +11,7 @@ router.get('/:id/history', Controller.history) router.get('/rentals/:id', Controller.rentalsTitle) router.get('/rentals/:id/customers', Controller.rentalsCustomers) -router.post('/rentals/:id/checkout', Controller.checkout) -router.patch('/rentals/:id/return', Controller.return) +router.post('/rentals/:id/checkout/:customer', Controller.checkout) +router.patch('/rentals/:id/return/:customer', Controller.return) router.get('/rentals/overdue', Controller.overdue) module.exports = router; From 465c269e23a1482c6566d776943f2e65f08690de Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 16 Jun 2016 15:47:41 -0700 Subject: [PATCH 39/79] scaffolded return function --- controllers/movies.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 0bda6b860..35e74c89c 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -67,7 +67,7 @@ var MovieController = { } } }, -// NOT YET COMPLETE/FUNCTIONAL +// NOT YET COMPLETE/FUNCTIONAL rentalsCustomers: function (req, res, next) { res.send( @@ -79,10 +79,22 @@ var MovieController = { // )}, - return: function (req, res, next) { - res.send( - // - )}, + return: function (req, res, next) { + var movie_id = req.params.id + var customer_id = req.params.customer + + // find rental id# that matches movie_id and customer_id + // update that instance to checked_out false + + db.rentals.update({id: ID_NUM, checked_out: false}, function(err, rental){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(rental) + } + }); + )}, overdue: function (req, res, next) { res.send( From 378b6b30d5dce75baa354d66db21f11f0461c68d Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 10:12:47 -0700 Subject: [PATCH 40/79] updated movies/rentals/return route to a get --- routes/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/movies.js b/routes/movies.js index 68fccf253..564d8c568 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -12,6 +12,6 @@ router.get('/:id/history', Controller.history) router.get('/rentals/:id', Controller.rentalsTitle) router.get('/rentals/:id/customers', Controller.rentalsCustomers) router.post('/rentals/:id/checkout/:customer', Controller.checkout) -router.patch('/rentals/:id/return/:customer', Controller.return) +router.get('/rentals/:id/return/:customer', Controller.return) router.get('/rentals/overdue', Controller.overdue) module.exports = router; From 05362cf3404e564291e8fe94a6920d5a6e59e3cc Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 10:13:12 -0700 Subject: [PATCH 41/79] return function does what it's supposed to. might want to change what it renders on success --- controllers/movies.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 35e74c89c..310b0f113 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -79,22 +79,19 @@ var MovieController = { // )}, - return: function (req, res, next) { - var movie_id = req.params.id - var customer_id = req.params.customer - - // find rental id# that matches movie_id and customer_id - // update that instance to checked_out false + return: function (req, res, next) { + var movie_id = req.params.id + var customer_id = req.params.customer - db.rentals.update({id: ID_NUM, checked_out: false}, function(err, rental){ - if(err) { - var err = new Error("It's an error") - next(err) - } else { - res.json(rental) - } - }); - )}, + db.query("update rentals set checked_out = false where movie_id=$1 AND customer_id=$2", [movie_id,customer_id], function(err, updateRental){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json("Success - movie returned") + } + }); + }, overdue: function (req, res, next) { res.send( From 43597391a5766fcdd0e1c08c4aa2fd6e684e38e0 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 10:20:24 -0700 Subject: [PATCH 42/79] return route returns 200 success upon update --- controllers/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/movies.js b/controllers/movies.js index 310b0f113..e7325c1f2 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -88,7 +88,7 @@ var MovieController = { var err = new Error("It's an error") next(err) } else { - res.json("Success - movie returned") + res.json(200) } }); }, From 24d49ec7c3967c92806cbdd336599fa6900adb60 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 11:08:48 -0700 Subject: [PATCH 43/79] changed movies/returns/checkout to get --- routes/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/movies.js b/routes/movies.js index 564d8c568..976204446 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -11,7 +11,7 @@ router.get('/:id/history', Controller.history) router.get('/rentals/:id', Controller.rentalsTitle) router.get('/rentals/:id/customers', Controller.rentalsCustomers) -router.post('/rentals/:id/checkout/:customer', Controller.checkout) +router.get('/rentals/:id/checkout/:customer', Controller.checkout) router.get('/rentals/:id/return/:customer', Controller.return) router.get('/rentals/overdue', Controller.overdue) module.exports = router; From 362f02923ff2fa334cd85dd434ddc078c9d47da1 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 11:09:13 -0700 Subject: [PATCH 44/79] checkout function will create a new rental instance --- controllers/movies.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index e7325c1f2..1b10b634e 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -75,9 +75,31 @@ var MovieController = { )}, checkout: function (req, res, next) { - res.send( - // - )}, + var movie_id = req.params.id + var customer_id = req.params.customer + + var current_date = new Date() + var current_day = current_date.getDate() + var current_month = current_date.getMonth() + 1 + var current_year = current_date.getFullYear() + var check_out_date = current_year + "-" + current_month + "-" + current_day + + var future_date = new Date(current_date.getTime()+(14*24*60*60*1000)); + var future_day = future_date.getDate() + var future_month = future_date.getMonth() + 1 + var future_year = future_date.getFullYear() + var due_date = future_year + "-" + future_month + "-" + future_day + + db.query("insert into rentals (customer_id,movie_id,check_out_date,checked_out,due_date) values ($1,$2,$3,$4,$5)", [customer_id,movie_id,check_out_date,true,due_date], function(err, createRental){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(200) + } + }); + + }, return: function (req, res, next) { var movie_id = req.params.id From 49d563206217ef95fcf4ac03daa5eea25da4deb9 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 11:34:24 -0700 Subject: [PATCH 45/79] Methods all complete and functional for customer routes --- controllers/customers.js | 91 +++++++++++++++++++++++++++++++++------- routes/customers.js | 1 + 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 2ea75ea33..615c67daa 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -1,28 +1,89 @@ +var Massive = require("massive"); +var db = Massive.connectSync({db : "video_store"}); + var CustomerController = { + allCustomers: function (req, res, next) { + db.query("select * from customers", function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(customerRecords) + } + }); + }, + sortName: function (req, res, next) { - res.send( - // CODE TO RETRIEVE CUSTOMERS BY NAME HERE - ) }, + var n = req.query.n + var p = req.params.p + var limit = Number(p) * 10 //assumes 10 customer records per "page", unused + if (n === undefined) { + n = 10} // IMPERFECT - REVISIT AT REFACTOR + db.query("select * from customers order by name asc limit $1", [n], function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(customerRecords) + } + }); + }, sortDate: function (req, res, next) { - res.send( - // CODE TO RETRIEVE CUSTOMERS BY registered_at - ) }, + var n = req.query.n + var p = req.params.p + var limit = Number(p) * 10 //assumes 10 customer records per "page", unused + if (n === undefined) { + n = 10} // IMPERFECT - REVISIT AT REFACTOR + db.query("select * from customers order by registered_at asc limit $1", [n], function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(customerRecords) + } + }); + }, sortPostalCode: function (req, res, next) { - res.send( - // CODE TO RETRIEVE CUSTOMERS BY postal_code - ) }, + var n = req.query.n + var p = req.params.p + var limit = Number(p) * 10 //assumes 10 customer records per "page", unused + if (n === undefined) { + n = 10} // IMPERFECT - REVISIT AT REFACTOR + db.query("select * from customers order by postal_code asc limit $1", [n], function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(customerRecords) + } + }); + }, current: function (req, res, next) { - res.send( - // CODE TO RETRIEVE currently checked out rentals by customer - ) }, + var customerId = req.params.id + db.query("select * from rentals where checked_out = true and customer_id=$1 order by due_date asc", [customerId], function(err, movieRecords){ + if(err) { + var err = new Error(err.message) + next(err) + } else { + res.json(movieRecords) + } + }); + }, history: function (req, res, next) { - res.send( - // CODE TO RETRIEVE previously checked out rentals by customer - ) } + var customerId = req.params.id + db.query("select * from rentals where checked_out = false and customer_id=$1 order by due_date asc", [customerId], function(err, movieRecords){ + if(err) { + var err = new Error(err.mesage) + next(err) + } else { + res.json(movieRecords) + } + }); + } } module.exports = CustomerController diff --git a/routes/customers.js b/routes/customers.js index 789460454..4be718d55 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -3,6 +3,7 @@ var router = express.Router() var Controller = require('../controllers/customers') /* GET home page. */ +router.get('/', Controller.allCustomers) router.get('/sort/name', Controller.sortName) router.get('/sort/registered-at', Controller.sortDate) router.get('/sort/postal-code', Controller.sortPostalCode) From 5ab6d985f907a695d3f8e2cf5bc6abfc0a36c9d7 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 11:35:08 -0700 Subject: [PATCH 46/79] All methods added for movie routes, functional, wheee --- controllers/movies.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 35e74c89c..c8d71308d 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -51,28 +51,38 @@ var MovieController = { rentalsTitle: function (req, res, next) { var movie_id = req.params.id - db.query("select * from rentals where movie_id = $1 and checked_out = true"), [movie_id], function(err, rentalRecords) { + db.query("select * from rentals where movie_id = $1 and checked_out = true", [movie_id], function(err, rentalRecords) { if(err) { throw (new Error(err.message)) } else { - db.query("select * from movies where movie_id=$1 asc", [movie_id], function(err, movieRecords){ + db.query("select * from movies where id=$1", [movie_id], function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { - var available = movieRecords.inventory - rentalRecords.length + var available = movieRecords[0].inventory - rentalRecords.length res.json({movieRecords: movieRecords, available: available}) } }); } - } + }) }, -// NOT YET COMPLETE/FUNCTIONAL +// refactor with join if rentalsCustomers: function (req, res, next) { - res.send( - // - )}, + var movie_id = req.params.id + db.query("select * from rentals where movie_id = $1 and checked_out = true", [movie_id], function(err, rentalRecords) { + if(err) { + throw (new Error(err.message)) + } else { + var customerNumbers = [] + for (var record of rentalRecords) { + customerNumbers.push(record.customer_id) + } + res.json({customerIdNumbers: customerNumbers}) + }} + ) +}, checkout: function (req, res, next) { res.send( @@ -94,7 +104,7 @@ var MovieController = { res.json(rental) } }); - )}, + }, overdue: function (req, res, next) { res.send( From 172a5446acb322c69d90e4ab043932617ae66686 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 13:34:57 -0700 Subject: [PATCH 47/79] added movies / route --- routes/movies.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/movies.js b/routes/movies.js index 976204446..d2db37760 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -3,6 +3,7 @@ var router = express.Router() var Controller = require('../controllers/movies') /* GET home page. */ +router.get('/', Controller.allMovies) router.get('/sort/title', Controller.sortTitle) router.get('/sort/release', Controller.sortRelease) From 8efb96292987f72116c879c100818c98d4af46f6 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 13:35:13 -0700 Subject: [PATCH 48/79] added allMovies controller function for / path --- controllers/movies.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/controllers/movies.js b/controllers/movies.js index cde27e717..1683b513b 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -2,6 +2,20 @@ var Massive = require("massive"); var db = Massive.connectSync({db : "video_store"}); var MovieController = { + + allMovies: function (req, res, next) { + + db.query("select * from movies", function(err, movieRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(movieRecords) + } + }); + }, + + sortTitle: function (req, res, next) { db.query("select * from movies order by title", function(err, movieRecords){ From 3faea59267338bb7d9ff1ae7ce59929906e14eec Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 14:01:57 -0700 Subject: [PATCH 49/79] moved rentals/overdue route above rentals/:id route because it was getting stuck --- routes/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/movies.js b/routes/movies.js index d2db37760..24ee0bd30 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -10,9 +10,9 @@ router.get('/sort/release', Controller.sortRelease) router.get('/:id/current', Controller.current) router.get('/:id/history', Controller.history) +router.get('/rentals/overdue', Controller.overdue) router.get('/rentals/:id', Controller.rentalsTitle) router.get('/rentals/:id/customers', Controller.rentalsCustomers) router.get('/rentals/:id/checkout/:customer', Controller.checkout) router.get('/rentals/:id/return/:customer', Controller.return) -router.get('/rentals/overdue', Controller.overdue) module.exports = router; From 09714e0a53b70cc7cd638fcfba479b0b76b8e795 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 14:02:10 -0700 Subject: [PATCH 50/79] overdue controller function works --- controllers/movies.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 1683b513b..b0c2f66b7 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -15,7 +15,6 @@ var MovieController = { }); }, - sortTitle: function (req, res, next) { db.query("select * from movies order by title", function(err, movieRecords){ @@ -140,8 +139,15 @@ var MovieController = { }, overdue: function (req, res, next) { - res.send( - // - )} + db.query("SELECT customer_id, movie_id, check_out_date, due_date FROM rentals WHERE checked_out=true AND due_date < now()", function(err, movieRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + res.json(movieRecords) + } + }); + } + } module.exports = MovieController From 4ea964759b64f70dcee775effc78fde25db17a0b Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 14:16:35 -0700 Subject: [PATCH 51/79] Fixed customer info show for current and history sorts --- controllers/movies.js | 59 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index cde27e717..d2b2d22f1 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -32,19 +32,70 @@ var MovieController = { var err = new Error("It's an error") next(err) } else { - res.json(movieRecords) + var customers = [] + for (var movie of movieRecords) { + db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + customers.push(customerRecords) + // console.log(customers) + } + res.json(customers) + + } + )} + } + } + )}, + + historyName: function (req, res, next) { + var movie_id = req.params.id + db.query("select * from rentals where checked_out = false and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + var customers = [] + for (var movie of movieRecords) { + db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + customers.push(customerRecords) + // console.log(customers) + } + res.json(customers) + + } + )} } }); }, - history: function (req, res, next) { + historyDate: function (req, res, next) { var movie_id = req.params.id - db.query("select * from rentals where checked_out = false and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ + db.query("select * from rentals where checked_out = false and movie_id=$1 order by checked_out asc", [movie_id], function(err, movieRecords){ if(err) { var err = new Error("It's an error") next(err) } else { - res.json(movieRecords) + var customers = [] + for (var movie of movieRecords) { + db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ + if(err) { + var err = new Error("It's an error") + next(err) + } else { + customers.push(customerRecords) + // console.log(customers) + } + res.json(customers) + + } + )} } }); }, From def6b6f95f7ec2f425503f6b79d5c8d6bcbebc09 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 14:26:33 -0700 Subject: [PATCH 52/79] added start-test and test scripts --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 4970866e1..d6fbbff56 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", + "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", "db:create": "createdb video_store", "db:seed": "clear; node tasks/db_seed.js", From 4de6aee2bcd142c03f66d99ae2a2abc01e8409fb Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 17 Jun 2016 14:27:28 -0700 Subject: [PATCH 53/79] added customers controller spec file --- spec/controllers/customers.spec.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) 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..e69de29bb From da60debe4863b1b847a7488a979d2b82fd5e8a72 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 14:48:24 -0700 Subject: [PATCH 54/79] added n and p to queries involving configurable sorting --- controllers/customers.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 615c67daa..3800cfc1f 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -15,11 +15,10 @@ var CustomerController = { sortName: function (req, res, next) { var n = req.query.n - var p = req.params.p - var limit = Number(p) * 10 //assumes 10 customer records per "page", unused - if (n === undefined) { - n = 10} // IMPERFECT - REVISIT AT REFACTOR - db.query("select * from customers order by name asc limit $1", [n], function(err, customerRecords){ + var p = req.query.p + if (n === undefined) { n = 10 } + if ( p === undefined) { p = 1 } + db.query("select * from customers order by name asc limit $1 offset $2", [n, p], function(err, customerRecords){ if(err) { var err = new Error("It's an error") next(err) @@ -31,11 +30,10 @@ var CustomerController = { sortDate: function (req, res, next) { var n = req.query.n - var p = req.params.p - var limit = Number(p) * 10 //assumes 10 customer records per "page", unused - if (n === undefined) { - n = 10} // IMPERFECT - REVISIT AT REFACTOR - db.query("select * from customers order by registered_at asc limit $1", [n], function(err, customerRecords){ + var p = req.query.p + if ( n === undefined) { n = 10 } + if ( p === undefined) { p = 1 } + db.query("select * from customers order by registered_at asc limit $1 offset $2", [n], function(err, customerRecords){ if(err) { var err = new Error("It's an error") next(err) @@ -48,10 +46,9 @@ var CustomerController = { sortPostalCode: function (req, res, next) { var n = req.query.n var p = req.params.p - var limit = Number(p) * 10 //assumes 10 customer records per "page", unused - if (n === undefined) { - n = 10} // IMPERFECT - REVISIT AT REFACTOR - db.query("select * from customers order by postal_code asc limit $1", [n], function(err, customerRecords){ + if ( n === undefined) { n = 10 } + if ( p === undefined) { p = 1 } + db.query("select * from customers order by postal_code asc limit $1", [n, p], function(err, customerRecords){ if(err) { var err = new Error("It's an error") next(err) From 78d72afdcfd3ae3eaa5c72271f76af11595ba7ae Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 14:49:28 -0700 Subject: [PATCH 55/79] movies controller with custome information displayed in current/history retrieval, plus n and p query functionality --- controllers/movies.js | 50 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 790fef77f..5526bcf52 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -7,7 +7,7 @@ var MovieController = { db.query("select * from movies", function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(movieRecords) @@ -16,10 +16,13 @@ var MovieController = { }, sortTitle: function (req, res, next) { - - db.query("select * from movies order by title", function(err, movieRecords){ + var n = req.query.n + var p = req.query.p + if ( n === undefined) { n = 10 } + if ( p === undefined) { p = 1 } + db.query("select * from movies order by title limit $1 offset $2", [n, p], function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(movieRecords) @@ -28,9 +31,13 @@ var MovieController = { }, sortRelease: function (req, res, next) { - db.query("select * from movies order by release_date", function(err, movieRecords){ + var n = req.query.n + var p = req.query.p + if ( n === undefined) { n = 10 } + if ( p === undefined) { p = 1 } + db.query("select * from movies order by release_date limit $1 offset $2", [n, p], function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(movieRecords) @@ -41,15 +48,19 @@ var MovieController = { current: function (req, res, next) { var movie_id = req.params.id db.query("select * from rentals where checked_out = true and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ + console.log(movieRecords) if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) - } else { + } else if (movieRecords.length < 1) { + res.json("This movie has not been checked out yet") + } + else { var customers = [] for (var movie of movieRecords) { db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { customers.push(customerRecords) @@ -67,14 +78,17 @@ var MovieController = { var movie_id = req.params.id db.query("select * from rentals where checked_out = false and movie_id=$1 order by due_date asc", [movie_id], function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) + } else if (movieRecords.length < 1) { + res.json("This movie has not been checked out yet") } else { var customers = [] for (var movie of movieRecords) { - db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ + db.query("select * from customers where id=$1 order by name", [movie.customer_id], function(err, customerRecords){ + console.log("HERE") if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { customers.push(customerRecords) @@ -92,14 +106,16 @@ var MovieController = { var movie_id = req.params.id db.query("select * from rentals where checked_out = false and movie_id=$1 order by checked_out asc", [movie_id], function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) + } else if (movieRecords.length < 1) { + res.json("This movie has not been checked out yet") } else { var customers = [] for (var movie of movieRecords) { db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { customers.push(customerRecords) @@ -166,7 +182,7 @@ var MovieController = { db.query("insert into rentals (customer_id,movie_id,check_out_date,checked_out,due_date) values ($1,$2,$3,$4,$5)", [customer_id,movie_id,check_out_date,true,due_date], function(err, createRental){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(200) @@ -181,7 +197,7 @@ var MovieController = { db.query("update rentals set checked_out = false where movie_id=$1 AND customer_id=$2", [movie_id,customer_id], function(err, updateRental){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(200) @@ -192,7 +208,7 @@ var MovieController = { overdue: function (req, res, next) { db.query("SELECT customer_id, movie_id, check_out_date, due_date FROM rentals WHERE checked_out=true AND due_date < now()", function(err, movieRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(movieRecords) From 644b1dbaeda6f022151c89353cf0866e0993b1ed Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 14:49:47 -0700 Subject: [PATCH 56/79] fixed route for sorting by release-date --- routes/movies.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/movies.js b/routes/movies.js index 24ee0bd30..f6afe52e2 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -5,10 +5,11 @@ var Controller = require('../controllers/movies') /* GET home page. */ router.get('/', Controller.allMovies) router.get('/sort/title', Controller.sortTitle) -router.get('/sort/release', Controller.sortRelease) +router.get('/sort/release-date', Controller.sortRelease) router.get('/:id/current', Controller.current) -router.get('/:id/history', Controller.history) +router.get('/:id/history/sort/date', Controller.historyDate) +router.get('/:id/history/sort/name', Controller.historyName) router.get('/rentals/overdue', Controller.overdue) router.get('/rentals/:id', Controller.rentalsTitle) From a60b62fb5fbd5b7f8442ae3b57878fea3aec07a5 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Fri, 17 Jun 2016 14:55:53 -0700 Subject: [PATCH 57/79] all endpoints complete and functionally tested. Formal testing next --- controllers/customers.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 3800cfc1f..c7f50ed2f 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -5,7 +5,7 @@ var CustomerController = { allCustomers: function (req, res, next) { db.query("select * from customers", function(err, customerRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(customerRecords) @@ -20,7 +20,7 @@ var CustomerController = { if ( p === undefined) { p = 1 } db.query("select * from customers order by name asc limit $1 offset $2", [n, p], function(err, customerRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(customerRecords) @@ -33,9 +33,9 @@ var CustomerController = { var p = req.query.p if ( n === undefined) { n = 10 } if ( p === undefined) { p = 1 } - db.query("select * from customers order by registered_at asc limit $1 offset $2", [n], function(err, customerRecords){ + db.query("select * from customers order by registered_at asc limit $1 offset $2", [n, p], function(err, customerRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(customerRecords) @@ -45,12 +45,12 @@ var CustomerController = { sortPostalCode: function (req, res, next) { var n = req.query.n - var p = req.params.p + var p = req.query.p if ( n === undefined) { n = 10 } if ( p === undefined) { p = 1 } - db.query("select * from customers order by postal_code asc limit $1", [n, p], function(err, customerRecords){ + db.query("select * from customers order by postal_code asc limit $1 offset $2", [n, p], function(err, customerRecords){ if(err) { - var err = new Error("It's an error") + var err = new Error(err.message) next(err) } else { res.json(customerRecords) From e5f18d0c764f9ffcdb242e1a4695460f8321bcc9 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 10:41:48 -0700 Subject: [PATCH 58/79] checkout function deducts from customers account --- controllers/movies.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/controllers/movies.js b/controllers/movies.js index b0c2f66b7..2ba26921c 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -118,7 +118,14 @@ var MovieController = { var err = new Error("It's an error") next(err) } else { - res.json(200) + db.query("update customers set account_credit = account_credit - 1 where id = $1", [customer_id], function(err, customerRecord){ + if(err) { + var err = new Error(err.message) + next(err) + } else { + res.json(200) + } + }); } }); From 8e7ff34eda22dd4feac2439d4cd8c9ed8d18d1c2 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 13:50:31 -0700 Subject: [PATCH 59/79] checkout and return are now posts instead of gets. works in postman so thats cool --- routes/movies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/movies.js b/routes/movies.js index f6afe52e2..db230d2fd 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -14,6 +14,6 @@ router.get('/:id/history/sort/name', Controller.historyName) router.get('/rentals/overdue', Controller.overdue) router.get('/rentals/:id', Controller.rentalsTitle) router.get('/rentals/:id/customers', Controller.rentalsCustomers) -router.get('/rentals/:id/checkout/:customer', Controller.checkout) -router.get('/rentals/:id/return/:customer', Controller.return) +router.post('/rentals/:id/checkout/:customer', Controller.checkout) +router.post('/rentals/:id/return/:customer', Controller.return) module.exports = router; From 43b76132c9c06ef032fd2bb31f18c45e1786cdef Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 14:03:39 -0700 Subject: [PATCH 60/79] installed istanbul --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index d6fbbff56..45234228b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,9 @@ "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", "sequelize": "^3.23.3", From 50e98296452598214296fb38f37ce32fe19d1b60 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 14:11:23 -0700 Subject: [PATCH 61/79] remove coverage from git tracking --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 646ac519e..e4259ac40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store node_modules/ +coverage From 0cd3c08c9c5c4239a18346874f0527e7216973b0 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 14:11:40 -0700 Subject: [PATCH 62/79] updated test script to include instanbul and it works yey --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 45234228b..75814f8fd 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "nodemon ./bin/www", "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/", + "test": "clear; ./node_modules/.bin/istanbul cover --include-all-sources ./node_modules/.bin/jasmine-node --verbose spec/", "db:create": "createdb video_store", "db:seed": "clear; node tasks/db_seed.js", "db:drop": "dropdb video_store", From 57a09ab9323ed07548e38bbcde21844d1d723d28 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Mon, 20 Jun 2016 14:31:26 -0700 Subject: [PATCH 63/79] Created documentation for our API, have not yet connected its existence to serve it up JSON or HTML --- README.md | 138 +++++++++++++++++---------------------- controllers/customers.js | 4 ++ controllers/movies.js | 8 ++- lib/documentation.js | 0 routes/index.js | 5 ++ 5 files changed, 75 insertions(+), 80 deletions(-) create mode 100644 lib/documentation.js diff --git a/README.md b/README.md index b38c92359..362b5c41d 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,82 @@ -# Project: VideoStoreAPI -The overall goal of this project is to create a system that a video store (remember those?) could use to track their inventory of rental videos and their collection of customers. +- All endpoints return JSON data unless explicitly stated otherwise. If there is no data/record to return a message such as "This movie has not yet been checked out" or "This customer has not yet checked out a movie" will be returned. -We will use [NodeJS](https://nodejs.org/en/) and [Express](http://expressjs.com/) to construct a RESTful API. The goal of this API is to quickly serve information about the store's video collection, customer information, and to update rental status. This repository provides two JSON datafiles to serve as the initial seeds for this system. - -## Project Baseline -- Read the API Requirements below and create a pseudo-code "routes" file that - - defines the _endpoints_ your API will need - - the _HTTP verbs_ each endpoint will use - - and any data that must be provided to the endpoint in order for it to do its work. -- Create a new Node/Express app to serve as the API. -- Create a route that responds to `/zomg` that serves a json-encoded "it works!" method. - -## Wave 1: Database Models, Tables, & Seeds -- Create an ERD for your database by reading through all of the requirements below. -- Be sure your ERD includes primary keys for all tables -- Leverage MassiveJS and create custom npm scripts to... - - create a development database - - drop a development database - - apply a schema to the database - - seed a database using the provided json data in `db/seeds` - -### Seed Data -`movies.json` contains information about the videos available to rent at the store. The data is presented as an array of objects, with each object having the following key-value pairs: - -- `title`: The title of the film -- `overview`: A short plot synopsis -- `release_date`: When the film was originally released -- `inventory`: How many copies of the film the video store owns - -`customers.json` contains information about the customers that have rented with the store in the past. The data is presented as, you guessed it, an array of objects, with each object have the following key-value pairs: - -- `name`: The customer's name -- `registered_at`: When the customer first visited the store -- The customer's physical address, composed of: - - `address` - - `city` - - `state` - - `postal_code` -- `phone`: Primary contact phone number -- `account_credit`: For reason we'd rather not get into, the store owes all of their customers a little bit of money; this amount is made available to customers as credit toward future rentals. - -## Wave 2: API Requirements -The API you build should have the following capabilities. The schema of your database and the structure of the endpoints are completely up to you. Make every effort to conform to RESTful routing patterns. Every endpoint (except for `/zomg` from the baseline) must serve `json` data. Use HTTP response codes to indicate the status of the request. - -#### Authentication -- There is not an authentication requirement for this project; assume all users interacting with the API are video store employees. - -#### Interface -- This part of the project is purely an API; all interactions should happen over HTTP requests. There is no front-end, user-facing interface. +- All endpoints are assumed to be GET unless explicitly stated otherwise #### Customers -- Retrive a list of all customers (`/customers`) -- Retrive a subset of customers (`/customers/sort/name?n=10&p=2`) +- Retrive a list of all customers: (`/customers`) +- Retrive a subset of customers (`/customers/sort/:sort_params`) - Given a sort column, return _n_ customer records, offset by _p_ records (this will be used to create "pages" of customers) - - Sort columns are - - `name` - - `registered_at` - - `postal_code` + - Sort params are + - `name` : (`/name?n=10&p=2`) + - `registered_at` example: (`/registered-at?n=10&p=2`) + - `postal_code` example: (`/postal-code?n=10&p=2`) - Given a customer's `id`... - - 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`) + - List the movies they _currently_ have checked out (`/customers/:customer_id/current`) + - List the movies a customer has checked out in the past (`/customers/:customer_id/history`) - ordered by check out date - includes return date #### Movies - Retrieve a list of all movies (`/movies`) -- Retrieve a subset of movies (`/movies/sort/release-date?n=5&p=1`) +- Retrieve a subset of movies (`/movies/sort/:sort_params`) - Given a sort column, return _n_ movie records, offset by _p_ records (this will be used to create "pages" of movies) - - Sort columns are - - `title` - - `release_date` -- Given a movie's `title`... - - Get a list of customers that have _currently_ checked out a copy of the film (`/movies/Jaws/current`) - - include each customer's name, phone number, and account credit - - Get a list of customers that have checked out a copy _in the past_ (`/movies/Jaws/history/sort/name`) - - include each customer's name, phone number, and account credit - - ordered by customer `name` __or__ - - ordered by check out date + - Sort params are + - `title` example: (`/title?n=5&p=1`) + - `release_date` example: (`/release-date?n=5&p=1`) +- Given a movie's `id`... + - Get a list of customers that have _currently_ checked out a copy of the film (`/movies/:movie_id/current`) + - includes each customer's name, phone number, and account credit + - Get a list of customers that have checked out a copy _in the past_ + - includes each customer's name, phone number, and account credit + - ordered by customer `name` (`/movies/:movie_id/history/sort/name`) + - ordered by `check-out` (`/movies/:movie_id/history/sort/date`) #### Rental -- Look a movie up by title to see (`/rentals/Jaws`) +- Look a movie up by id to see (`/movies/rentals/2`) - it's synopsis - release date - - available inventory (not currently checked-out to a customer) + - available inventory (not currently checked-out to a customer) - and inventory total -- See a list of customers that have _currently_ checked out any of the movie's inventory (`/rentals/Jaws/customers`) +- See a list of customers that have _currently_ checked out any of the movie's inventory (`/movies/rentals/:movie_id/customers`) - Given a customer's `id` and a movie's `title` ... - - "check out" one of the movie's inventory to the customer (`/rentals/Jaws/check-out`) + - "check out" one of the movie's inventory to the customer POST (`/movies/rentals/:movie_id/check-out/:customer_id`) - Establish a return date - Charge the customer's account (cost up to you) - - "check in" one of customer's rentals (`/rentals/Jaws/return`) + - "check in" one of customer's rentals POST (`/movies/rentals/:movie_id/return/:customer_id`) - return the movie to its inventory -- See a list of customers with overdue movies (`/rentals/overdue`) +- See a list of customers with overdue movies (`/movies/rentals/overdue`) - include customer name, movie title, check-out date, and return date -#### Testing -- All endpoints must be tested. -- We will use [Jasmine](https://github.com/mhevery/jasmine-node) for tests. -- There isn't a coverage requirement for this project, beyond demonstrating that every endpoint is covered by some manner of tests. + ================================= + +####Visual tree +All urls are from root (localhost:3000/) + +- (`/customers`) (All customers) + - (`/customers/sort/:sort_params`) (Some customers) + + `name` : (`/name?n=10&p=2`) (sorted by name) + + `registered_at` : (`/registered-at?n=10&p=2`) (sortedby join date) + + `postal_code` : (`/postal-code?n=10&p=2`) (sorted by location) + - (`/customers/:customer_id/current`) (Currently checked out movies by a customer) + - (`/customers/:customer_id/history`) (Previously checked out movies by a customer) + + +- (`/movies`) (All movies) + - (`/movies/sort/:sort_params`) (Some movies) + + `title` : (`/title?n=5&p=1`) (Sorted by title) + + `release_date` : (`/release-date?n=5&p=1`) (Sorted by release date) + - (`/movies/:movie_id/current`) (Current rentals per movie, ordered by due date) + - (`/movies/:movie_id/history/sort/:sort_params`) (Some customers who have previously checked out movies) + + (`/movies/:movie_id/history/sort/name`) (Sort by customer name) + + (`/movies/:movie_id/history/sort/date`) (Sort by check-out date) + +#####[Rentals, an extension of Movies] + - (`/movies/rentals/:movie_id`) (To see movie details, and number of available copies in addition to total stock) + - (`/movies/rentals/:movie_id/customers`) (Customers who currently have this movie checked out) + - POST (`/movies/rentals/:movie_id/check-out/:customer_id`) (Creates a "check-out" of this movie to this customer, assigning the record a due date and charge) + - POST (`/movies/rentals/:movie_id/return/:customer_id`) ("Returns" this movie checked out to this customer, changing checked-out status to false, and changing the available inventory accordingly) + - (`/movies/rentals/overdue`) + +##Informational endpoints +- (`/api/docs`) (Serves a *HTML view* of documentation) +- (`/api/docs.json`) (Serves JSON documentation) diff --git a/controllers/customers.js b/controllers/customers.js index c7f50ed2f..f200d26bb 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -64,6 +64,8 @@ var CustomerController = { if(err) { var err = new Error(err.message) next(err) + } else if (movieRecords.length < 1) { + res.json("This customer has not yet checked out any movies") } else { res.json(movieRecords) } @@ -76,6 +78,8 @@ var CustomerController = { if(err) { var err = new Error(err.mesage) next(err) + } else if (movieRecords.length < 1) { + res.json("This customer has not yet checked out any movies") } else { res.json(movieRecords) } diff --git a/controllers/movies.js b/controllers/movies.js index ebb44ce3b..a2af3c3d6 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -134,7 +134,9 @@ var MovieController = { db.query("select * from rentals where movie_id = $1 and checked_out = true", [movie_id], function(err, rentalRecords) { if(err) { throw (new Error(err.message)) - } else { + } else if (movieRecords.length < 1) { + res.json("This movie has not been checked out yet") + }else { db.query("select * from movies where id=$1", [movie_id], function(err, movieRecords){ if(err) { var err = new Error(err.message) @@ -154,7 +156,9 @@ var MovieController = { db.query("select * from rentals where movie_id = $1 and checked_out = true", [movie_id], function(err, rentalRecords) { if(err) { throw (new Error(err.message)) - } else { + } else if (movieRecords.length < 1) { + res.json("This movie has not been checked out yet") + }else { var customerNumbers = [] for (var record of rentalRecords) { customerNumbers.push(record.customer_id) diff --git a/lib/documentation.js b/lib/documentation.js new file mode 100644 index 000000000..e69de29bb diff --git a/routes/index.js b/routes/index.js index 51c5c6268..c2d520131 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,6 @@ var express = require('express'); var router = express.Router(); +var documentation = require('../lib/documentation') /* GET home page. */ @@ -11,4 +12,8 @@ router.get('/zomg', function(req, res, next) { res.status(200).json({whatevs: 'it works!!!'}) }); +router.get('/api/docs', function(req, res, next) { + res.status(200).json({whatevs: 'whatevs!!!'}) +}); + module.exports = router; From 9aee2be0bd4922bf9eedf655afd4201f5a5b18d1 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 15:04:15 -0700 Subject: [PATCH 64/79] tests for /movies route --- spec/controllers/movies.spec.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index ddcaf2f68..8e8ea9aa6 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,5 +1,26 @@ -var request = require('request'); +var request = require('request') +var base_url = "http://localhost:3000/movies" -describe("Endpoints under /movies", function() { - +describe("Endpoint at /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() + }) + }) + + it("returns JSON", function(done) { + request.get(base_url, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + it('has the right values', function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(data['0'].title).toEqual('Psycho') + done() + }) + }) }) From aa195e6b9a07e41cee8b7c5ecc0162391f3d76d4 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Mon, 20 Jun 2016 15:15:20 -0700 Subject: [PATCH 65/79] testing for /customers --- spec/controllers/customers.spec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index e69de29bb..a0586ac84 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -0,0 +1,26 @@ +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() + }) + }) + + it("returns JSON", function(done) { + request.get(base_url, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + it('has the right values', function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(data['0'].city).toEqual('Harrisburg') + done() + }) + }) +}) From 4a3e3aa173f771715c69eafd21ecd280abc925c6 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Mon, 20 Jun 2016 16:16:42 -0700 Subject: [PATCH 66/79] Added .json documentation endpoint, successful. --- lib/documentation.js | 0 package.json | 2 + routes/index.js | 11 +++- views/index.jade | 6 +- views/plain.html | 153 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+), 8 deletions(-) delete mode 100644 lib/documentation.js create mode 100644 views/plain.html diff --git a/lib/documentation.js b/lib/documentation.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/package.json b/package.json index 75814f8fd..75c0515d3 100644 --- a/package.json +++ b/package.json @@ -17,9 +17,11 @@ "cookie-parser": "~1.3.5", "debug": "~2.2.0", "express": "~4.13.1", + "himalaya": "^0.2.0", "istanbul": "^0.4.4", "jade": "~1.11.0", "jasmine-node": "^1.14.5", + "markdown": "^0.5.0", "massive": "^2.3.0", "morgan": "~1.6.1", "sequelize": "^3.23.3", diff --git a/routes/index.js b/routes/index.js index c2d520131..d7d9ce02b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,7 +1,8 @@ var express = require('express'); var router = express.Router(); -var documentation = require('../lib/documentation') - +var himalaya = require('himalaya'); +var html = require('fs').readFileSync('README.md'); +var json = himalaya.parse(html); //actually md. close enough. /* GET home page. */ router.get('/', function(req, res, next) { @@ -13,7 +14,11 @@ router.get('/zomg', function(req, res, next) { }); router.get('/api/docs', function(req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) + res.render('../views/index') +}); + +router.get('/api/docs.json', function(req, res, next) { + res.json(json) }); module.exports = router; diff --git a/views/index.jade b/views/index.jade index 3d63b9a04..1459f5280 100644 --- a/views/index.jade +++ b/views/index.jade @@ -1,5 +1 @@ -extends layout - -block content - h1= title - p Welcome to #{title} +include plain.html diff --git a/views/plain.html b/views/plain.html new file mode 100644 index 000000000..8e74fbedc --- /dev/null +++ b/views/plain.html @@ -0,0 +1,153 @@ +Video Store API Documentation +
    +
  • +

    All endpoints return JSON data unless explicitly stated otherwise. If there is no data/record to return a message such as “This movie has not yet been checked out” or “This customer has not yet checked out a movie” will be returned.

    +
  • +
  • +

    All endpoints are assumed to be GET unless explicitly stated otherwise

    +
  • +
+

Customers

+
    +
  • Retrive a list of all customers: (/customers)
  • +
  • Retrive a subset of customers (/customers/sort/:sort_params) +
      +
    • Given a sort column, return n customer records, offset by p records (this will be used to create “pages” of customers)
    • +
    • Sort params are +
        +
      • name : (/name?n=10&p=2)
      • +
      • registered_at example: (/registered-at?n=10&p=2)
      • +
      • postal_code example: (/postal-code?n=10&p=2)
      • +
      +
    • +
    +
  • +
  • Given a customer’s id… +
      +
    • List the movies they currently have checked out (/customers/:customer_id/current)
    • +
    • List the movies a customer has checked out in the past (/customers/:customer_id/history) +
        +
      • ordered by check out date
      • +
      • includes return date
      • +
      +
    • +
    +
  • +
+

Movies

+
    +
  • Retrieve a list of all movies (/movies)
  • +
  • Retrieve a subset of movies (/movies/sort/:sort_params) +
      +
    • Given a sort column, return n movie records, offset by p records (this will be used to create “pages” of movies)
    • +
    • Sort params are +
        +
      • title example: (/title?n=5&p=1)
      • +
      • release_date example: (/release-date?n=5&p=1)
      • +
      +
    • +
    +
  • +
  • Given a movie’s id… +
      +
    • Get a list of customers that have currently checked out a copy of the film (/movies/:movie_id/current) +
        +
      • includes each customer’s name, phone number, and account credit
      • +
      +
    • +
    • Get a list of customers that have checked out a copy in the past +
        +
      • includes each customer’s name, phone number, and account credit
      • +
      • ordered by customer name (/movies/:movie_id/history/sort/name)
      • +
      • ordered by check-out (/movies/:movie_id/history/sort/date)
      • +
      +
    • +
    +
  • +
+

Rental

+
    +
  • +

    Look a movie up by id to see (/movies/rentals/2)

    +
      +
    • it’s synopsis
    • +
    • release date
    • +
    • available inventory (not currently checked-out to a customer)
    • +
    • and inventory total
    • +
    +
  • +
  • +

    See a list of customers that have currently checked out any of the movie’s inventory (/movies/rentals/:movie_id/customers)

    +
  • +
  • +

    Given a customer’s id and a movie’s title

    +
      +
    • “check out” one of the movie’s inventory to the customer POST (/movies/rentals/:movie_id/check-out/:customer_id) +
        +
      • Establish a return date
      • +
      • Charge the customer’s account (cost up to you)
      • +
      +
    • +
    • “check in” one of customer’s rentals POST (/movies/rentals/:movie_id/return/:customer_id) +
        +
      • return the movie to its inventory
      • +
      +
    • +
    +
  • +
  • +

    See a list of customers with overdue movies (/movies/rentals/overdue)

    +
      +
    • include customer name, movie title, check-out date, and return date
    • +
    +

    =================================

    +
  • +
+

Visual tree

+All urls are from root (localhost:3000/)

+
    +
  • (/customers) (All customers)
  • +
  • (/customers/sort/:sort_params) (Some customers) +
      +
    • name : (/name?n=10&p=2) (sorted by name)
    • +
    • registered_at : (/registered-at?n=10&p=2) (sortedby join date)
    • +
    • postal_code : (/postal-code?n=10&p=2) (sorted by location)
    • +
    +
  • +
  • (/customers/:customer_id/current) (Currently checked out movies by a customer)
  • +
  • (/customers/:customer_id/history) (Previously checked out movies by a customer)
  • +
+
    +
  • (/movies) (All movies) +
      +
    • (/movies/sort/:sort_params) (Some movies) +
        +
      • title : (/title?n=5&p=1) (Sorted by title)
      • +
      • release_date : (/release-date?n=5&p=1) (Sorted by release date)
      • +
      +
    • +
    • (/movies/:movie_id/current) (Current rentals per movie, ordered by due date)
    • +
    • (/movies/:movie_id/history/sort/:sort_params) (Some customers who have previously checked out movies) +
        +
      • (/movies/:movie_id/history/sort/name) (Sort by customer name)
      • +
      • (/movies/:movie_id/history/sort/date) (Sort by check-out date)
      • +
      +
    • +
    +
  • +
+

[Rentals, an extension of Movies]

+
    +
  • (/movies/rentals/:movie_id) (To see movie details, and number of available copies in addition to total stock)
  • +
  • (/movies/rentals/:movie_id/customers) (Customers who currently have this movie checked out)
  • +
  • POST (/movies/rentals/:movie_id/check-out/:customer_id) (Creates a “check-out” of this movie to this customer, assigning the record a due date and charge)
  • +
  • POST (/movies/rentals/:movie_id/return/:customer_id) (“Returns” this movie checked out to this customer, changing checked-out status to false, and changing the available inventory accordingly)
  • +
  • (/movies/rentals/overdue)
  • +
+

Informational endpoints

+
    +
  • (/api/docs) (Serves a HTML view of documentation)
  • +
  • (/api/docs.json) (Serves JSON documentation)
  • +
+ + From 3e8b8169aa8c27d6e23cf8dac80097d077bd2386 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Tue, 21 Jun 2016 10:00:27 -0700 Subject: [PATCH 67/79] added array of objects tests for movies and cusomters --- spec/controllers/customers.spec.js | 24 ++++++++++++++++++------ spec/controllers/movies.spec.js | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index a0586ac84..b4f730392 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -16,11 +16,23 @@ describe("Endpoint at /customers", function () { }) }) - it('has the right values', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(data['0'].city).toEqual('Harrisburg') - done() - }) + it("should be an array of objects", function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(typeof data).toEqual('object') + + for (var record of data) { + expect(Object.keys(record)).toEqual([ 'id', 'name', 'address', 'city', 'state', 'postal_code', 'phone', 'account_credit', 'registered_at']) + } + done() }) + }) + + it('has the right values', function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(data['0'].city).toEqual('Hillsboro') + done() + }) + }) }) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 8e8ea9aa6..038bd2e00 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -16,11 +16,23 @@ describe("Endpoint at /movies", function () { }) }) - it('has the right values', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(data['0'].title).toEqual('Psycho') - done() - }) + it("should be an array of objects", function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(typeof data).toEqual('object') + + for (var record of data) { + expect(Object.keys(record)).toEqual([ 'id', 'title', 'overview', 'inventory', 'available', 'release_date']) + } + done() }) + }) + + it('has the right values', function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(data['0'].title).toEqual('Psycho') + done() + }) + }) }) From 8dc8e1e35eb1a0d6c6a970f80f5d4b9f1944b321 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Tue, 21 Jun 2016 13:28:10 -0700 Subject: [PATCH 68/79] Minor test change --- spec/controllers/customers.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index a0586ac84..e4e955ace 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -19,7 +19,7 @@ describe("Endpoint at /customers", function () { it('has the right values', function(done) { request.get(base_url, function(error, response, body) { var data = JSON.parse(body) - expect(data['0'].city).toEqual('Harrisburg') + expect(data[0].city).toEqual('Hillsboro') done() }) }) From e9121ecbc5d7b33ffce9b80199b8c52c12d3dd41 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Tue, 21 Jun 2016 13:48:11 -0700 Subject: [PATCH 69/79] test coverage for more endpoints in movies --- spec/controllers/movies.spec.js | 76 +++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 12 deletions(-) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 038bd2e00..69ac0c138 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,38 +1,90 @@ var request = require('request') -var base_url = "http://localhost:3000/movies" +var base_url = "http://localhost:3000" -describe("Endpoint at /movies", function () { +////sample shizz +var endpoints = ['/movies', '/movies/sort/title', '/movies/sort/release-date', '/movies/1/current', '/movies/1/history/sort/name', '/movies/1/history/sort/date', '/movies/rentals/1', '/movies/rentals/1/customers', '/movies/rentals/overdue'] + +for (var endpoint of endpoints) { + +describe("Endpoint at " + endpoint, function () { it('responds with a 200 status code', function (done) { - request.get(base_url, function(error, response, body) { + request.get(base_url + endpoint, function(error, response, body) { expect(response.statusCode).toEqual(200) done() }) }) it("returns JSON", function(done) { - request.get(base_url, function(error, response, body) { + request.get(base_url + endpoint, function(error, response, body) { expect(response.headers['content-type']).toContain('application/json') done() }) }) it("should be an array of objects", function(done) { - request.get(base_url, function(error, response, body) { + request.get(base_url + endpoint, function(error, response, body) { var data = JSON.parse(body) expect(typeof data).toEqual('object') + if (data.length === 6) { for (var record of data) { expect(Object.keys(record)).toEqual([ 'id', 'title', 'overview', 'inventory', 'available', 'release_date']) } done() + } else { + for (var record of data) { + expect(Object.keys(record)).toEqual([ 'customer_id', 'movie_id', 'check_out_date', 'due_date' ]) + } + done() + } + }) }) - it('has the right values', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(data['0'].title).toEqual('Psycho') - done() - }) - }) + // it('has the right values', function(done) { + // request.get(base_url + endpoint, function(error, response, body) { + // var data = JSON.parse(body) + // expect(data['0'].title).toEqual('Psycho') + // done() + // }) + // }) }) +}; //end of loop + +/////ORIGINAL STUFF BELOW + +// describe("Endpoint at /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() +// }) +// }) +// +// it("returns JSON", function(done) { +// request.get(base_url, function(error, response, body) { +// expect(response.headers['content-type']).toContain('application/json') +// done() +// }) +// }) +// +// it("should be an array of objects", function(done) { +// request.get(base_url, function(error, response, body) { +// var data = JSON.parse(body) +// expect(typeof data).toEqual('object') +// +// for (var record of data) { +// expect(Object.keys(record)).toEqual([ 'id', 'title', 'overview', 'inventory', 'available', 'release_date']) +// } +// done() +// }) +// }) +// +// it('has the right values', function(done) { +// request.get(base_url, function(error, response, body) { +// var data = JSON.parse(body) +// expect(data['0'].title).toEqual('Psycho') +// done() +// }) +// }) +// }) From 5b5a97817ae8079618bdfb96b3e4d754da8971d8 Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Wed, 22 Jun 2016 12:39:06 -0700 Subject: [PATCH 70/79] MERGE ALREADY --- spec/controllers/customers.spec.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 6cb092a08..5490ad56c 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -16,14 +16,7 @@ describe("Endpoint at /customers", function () { }) }) -<<<<<<< HEAD - it('has the right values', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(data[0].city).toEqual('Hillsboro') - done() - }) -======= + it("should be an array of objects", function(done) { request.get(base_url, function(error, response, body) { var data = JSON.parse(body) @@ -33,15 +26,8 @@ describe("Endpoint at /customers", function () { expect(Object.keys(record)).toEqual([ 'id', 'name', 'address', 'city', 'state', 'postal_code', 'phone', 'account_credit', 'registered_at']) } done() ->>>>>>> e9121ecbc5d7b33ffce9b80199b8c52c12d3dd41 }) }) - it('has the right values', function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(data['0'].city).toEqual('Hillsboro') - done() - }) }) }) From d21395e11c9afba3583b5eee8e608a34775ad5ab Mon Sep 17 00:00:00 2001 From: Nicole Iwasaki Date: Thu, 23 Jun 2016 09:18:57 -0700 Subject: [PATCH 71/79] Fixed tests, all pass; functional testing not being checked by istanbul --- package.json | 2 +- spec/controllers/customers.spec.js | 56 ++++++++++++---------- spec/controllers/movies.spec.js | 74 ++++++++++++++++-------------- 3 files changed, 71 insertions(+), 61 deletions(-) diff --git a/package.json b/package.json index 75c0515d3..10cb8674f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "nodemon ./bin/www", "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", - "test": "clear; ./node_modules/.bin/istanbul cover --include-all-sources ./node_modules/.bin/jasmine-node --verbose spec/", + "test": "clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --verbose spec/", "db:create": "createdb video_store", "db:seed": "clear; node tasks/db_seed.js", "db:drop": "dropdb video_store", diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 5490ad56c..dc8448497 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -1,33 +1,39 @@ var request = require('request') var base_url = "http://localhost:3000/customers" +var endpoints = ['/', '/customers', '/customers/sort/name', '/customers/sort/registered-at', '/customers/sort/postal-code', '/customers/2/current', '/customers/2/history'] -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("returns JSON", function(done) { - request.get(base_url, function(error, response, body) { - expect(response.headers['content-type']).toContain('application/json') - done() +var testing = function (endpoints) { + for (var endpoint of endpoints) { + 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("returns JSON", function(done) { + request.get(base_url, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) - it("should be an array of objects", function(done) { - request.get(base_url, function(error, response, body) { - var data = JSON.parse(body) - expect(typeof data).toEqual('object') + it("should be an array of objects", function(done) { + request.get(base_url, function(error, response, body) { + var data = JSON.parse(body) + expect(typeof data).toEqual('object') - for (var record of data) { - expect(Object.keys(record)).toEqual([ 'id', 'name', 'address', 'city', 'state', 'postal_code', 'phone', 'account_credit', 'registered_at']) - } - done() - }) - }) + for (var record of data) { + expect(Object.keys(record)).toEqual([ 'id', 'name', 'address', 'city', 'state', 'postal_code', 'phone', 'account_credit', 'registered_at']) + } + done() + }) + }) + + }) + } + } - }) -}) + testing(endpoints) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 69ac0c138..83ba4f38c 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -4,52 +4,56 @@ var base_url = "http://localhost:3000" ////sample shizz var endpoints = ['/movies', '/movies/sort/title', '/movies/sort/release-date', '/movies/1/current', '/movies/1/history/sort/name', '/movies/1/history/sort/date', '/movies/rentals/1', '/movies/rentals/1/customers', '/movies/rentals/overdue'] -for (var endpoint of endpoints) { +var testing = function(endpoints) { + for (var endpoint of endpoints) { + console.log(endpoint) -describe("Endpoint at " + endpoint, function () { - it('responds with a 200 status code', function (done) { - request.get(base_url + endpoint, function(error, response, body) { - expect(response.statusCode).toEqual(200) - done() - }) - }) - - it("returns JSON", function(done) { + describe("Endpoint at " + endpoint, function () { + it('responds with a 200 status code', function (done) { request.get(base_url + endpoint, function(error, response, body) { - expect(response.headers['content-type']).toContain('application/json') + expect(response.statusCode).toEqual(200) done() }) }) - it("should be an array of objects", function(done) { - request.get(base_url + endpoint, function(error, response, body) { - var data = JSON.parse(body) - expect(typeof data).toEqual('object') + it("returns JSON", function(done) { + request.get(base_url + endpoint, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) - if (data.length === 6) { - for (var record of data) { - expect(Object.keys(record)).toEqual([ 'id', 'title', 'overview', 'inventory', 'available', 'release_date']) - } - done() - } else { - for (var record of data) { - expect(Object.keys(record)).toEqual([ 'customer_id', 'movie_id', 'check_out_date', 'due_date' ]) + it("should be an array of objects", function(done) { + request.get(base_url + endpoint, function(error, response, body) { + var data = JSON.parse(body) + expect(typeof data).toEqual('object') + + if (data.length === 6) { + for (var record of data) { + expect(Object.keys(record)).toEqual([ 'id', 'title', 'overview', 'inventory', 'available', 'release_date']) + } + done() + } else { + for (var record of data) { + expect(Object.keys(record)).toEqual([ 'customer_id', 'movie_id', 'check_out_date', 'due_date' ]) + } + done() } - done() - } + }) }) - }) - // it('has the right values', function(done) { - // request.get(base_url + endpoint, function(error, response, body) { - // var data = JSON.parse(body) - // expect(data['0'].title).toEqual('Psycho') - // done() - // }) - // }) -}) -}; //end of loop + // it('has the right values', function(done) { + // request.get(base_url + endpoint, function(error, response, body) { + // var data = JSON.parse(body) + // expect(data['0'].title).toEqual('Psycho') + // done() + // }) + // }) + }) + }; //end of loop +} +testing(endpoints) /////ORIGINAL STUFF BELOW From 8d89d2c3150a55ab8816b64027c2802361c32085 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 23 Jun 2016 12:44:01 -0700 Subject: [PATCH 72/79] deleted a bracket because javascript --- spec/controllers/customers.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 5490ad56c..f114dd196 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -30,4 +30,3 @@ describe("Endpoint at /customers", function () { }) }) -}) From 3370f6bd43adf4531c995835151904572feb5b35 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Thu, 23 Jun 2016 13:00:50 -0700 Subject: [PATCH 73/79] refactored doubled sql commands --- controllers/movies.js | 22 ++++++++++------------ db/checked_out_movie_select.sql | 1 + db/customer_select.sql | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 db/checked_out_movie_select.sql create mode 100644 db/customer_select.sql diff --git a/controllers/movies.js b/controllers/movies.js index a2af3c3d6..8ecfdae96 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -58,7 +58,7 @@ var MovieController = { else { var customers = [] for (var movie of movieRecords) { - db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ + db.customer_select([movie.customer_id], function(err, customerRecords){ if(err) { var err = new Error(err.message) next(err) @@ -113,16 +113,14 @@ var MovieController = { } else { var customers = [] for (var movie of movieRecords) { - db.query("select * from customers where id=$1", [movie.customer_id], function(err, customerRecords){ - if(err) { - var err = new Error(err.message) - next(err) - } else { - customers.push(customerRecords) - // console.log(customers) - } + db.customer_select([movie.customer_id], function(err, customerRecords){ + if(err) { + var err = new Error(err.message) + next(err) + } else { + customers.push(customerRecords) + } res.json(customers) - } )} } @@ -131,7 +129,7 @@ var MovieController = { rentalsTitle: function (req, res, next) { var movie_id = req.params.id - db.query("select * from rentals where movie_id = $1 and checked_out = true", [movie_id], function(err, rentalRecords) { + db.checked_out_movie_select([movie_id], function(err, rentalRecords) { if(err) { throw (new Error(err.message)) } else if (movieRecords.length < 1) { @@ -153,7 +151,7 @@ var MovieController = { rentalsCustomers: function (req, res, next) { var movie_id = req.params.id - db.query("select * from rentals where movie_id = $1 and checked_out = true", [movie_id], function(err, rentalRecords) { + db.checked_out_movie_select([movie_id], function(err, rentalRecords) { if(err) { throw (new Error(err.message)) } else if (movieRecords.length < 1) { diff --git a/db/checked_out_movie_select.sql b/db/checked_out_movie_select.sql new file mode 100644 index 000000000..f07e0683e --- /dev/null +++ b/db/checked_out_movie_select.sql @@ -0,0 +1 @@ +select * from rentals where movie_id = $1 and checked_out = true; diff --git a/db/customer_select.sql b/db/customer_select.sql new file mode 100644 index 000000000..36f99e2d3 --- /dev/null +++ b/db/customer_select.sql @@ -0,0 +1 @@ +select * from customers where id=$1; From 226ab50e1889a35a1350fc51ac25f658de276871 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 24 Jun 2016 10:08:50 -0700 Subject: [PATCH 74/79] added details for checkout route --- views/plain.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/plain.html b/views/plain.html index 8e74fbedc..05f582331 100644 --- a/views/plain.html +++ b/views/plain.html @@ -84,8 +84,8 @@

Rental

  • “check out” one of the movie’s inventory to the customer POST (/movies/rentals/:movie_id/check-out/:customer_id)
      -
    • Establish a return date
    • -
    • Charge the customer’s account (cost up to you)
    • +
    • Establish a return date of 14 days from current date
    • +
    • Charge the customer’s account $1.00
  • “check in” one of customer’s rentals POST (/movies/rentals/:movie_id/return/:customer_id) From 6b1acb120012a2b8e00c5e3366a0cbf87850ccdd Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 24 Jun 2016 14:03:05 -0700 Subject: [PATCH 75/79] fixed bug with rentalstitle --- controllers/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/movies.js b/controllers/movies.js index 8ecfdae96..22b66f8db 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -132,7 +132,7 @@ var MovieController = { db.checked_out_movie_select([movie_id], function(err, rentalRecords) { if(err) { throw (new Error(err.message)) - } else if (movieRecords.length < 1) { + } else if (rentalRecords.length < 1) { res.json("This movie has not been checked out yet") }else { db.query("select * from movies where id=$1", [movie_id], function(err, movieRecords){ From 8cd23ace63538eb91f6efbdb49f1cb807259eb3d Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 24 Jun 2016 14:06:09 -0700 Subject: [PATCH 76/79] edited checkout URL --- views/plain.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/plain.html b/views/plain.html index 05f582331..20c337c8f 100644 --- a/views/plain.html +++ b/views/plain.html @@ -82,7 +82,7 @@

    Rental

  • Given a customer’s id and a movie’s title

      -
    • “check out” one of the movie’s inventory to the customer POST (/movies/rentals/:movie_id/check-out/:customer_id) +
    • “check out” one of the movie’s inventory to the customer POST (/movies/rentals/:movie_id/checkout/:customer_id)
      • Establish a return date of 14 days from current date
      • Charge the customer’s account $1.00
      • @@ -140,7 +140,7 @@

        [Rentals, an extension of Movies]

        • (/movies/rentals/:movie_id) (To see movie details, and number of available copies in addition to total stock)
        • (/movies/rentals/:movie_id/customers) (Customers who currently have this movie checked out)
        • -
        • POST (/movies/rentals/:movie_id/check-out/:customer_id) (Creates a “check-out” of this movie to this customer, assigning the record a due date and charge)
        • +
        • POST (/movies/rentals/:movie_id/checkout/:customer_id) (Creates a “check-out” of this movie to this customer, assigning the record a due date and charge)
        • POST (/movies/rentals/:movie_id/return/:customer_id) (“Returns” this movie checked out to this customer, changing checked-out status to false, and changing the available inventory accordingly)
        • (/movies/rentals/overdue)
        From 93668cc34288b5d2abf9600aad764eb3c0557fc6 Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 24 Jun 2016 14:18:26 -0700 Subject: [PATCH 77/79] added statement about errors --- views/plain.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/plain.html b/views/plain.html index 20c337c8f..74d0b5455 100644 --- a/views/plain.html +++ b/views/plain.html @@ -1,7 +1,7 @@ Video Store API Documentation
        • -

          All endpoints return JSON data unless explicitly stated otherwise. If there is no data/record to return a message such as “This movie has not yet been checked out” or “This customer has not yet checked out a movie” will be returned.

          +

          All endpoints return JSON data unless explicitly stated otherwise. If there is no data/record to return a message such as “This movie has not yet been checked out” or “This customer has not yet checked out a movie” will be returned. If there is an error, an error page will display.

        • All endpoints are assumed to be GET unless explicitly stated otherwise

          From 3158e465419594f600efa000a3415e251d71ac6e Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 24 Jun 2016 14:20:21 -0700 Subject: [PATCH 78/79] edited some so that errors will show --- controllers/movies.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 22b66f8db..ff7c5fcf0 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -131,7 +131,8 @@ var MovieController = { var movie_id = req.params.id db.checked_out_movie_select([movie_id], function(err, rentalRecords) { if(err) { - throw (new Error(err.message)) + var err = new Error(err.message) + next(err) } else if (rentalRecords.length < 1) { res.json("This movie has not been checked out yet") }else { @@ -153,7 +154,8 @@ var MovieController = { var movie_id = req.params.id db.checked_out_movie_select([movie_id], function(err, rentalRecords) { if(err) { - throw (new Error(err.message)) + var err = new Error(err.message) + next(err) } else if (movieRecords.length < 1) { res.json("This movie has not been checked out yet") }else { From 439fb49e642fbcc6d80eaea1713fc4de1f38c17b Mon Sep 17 00:00:00 2001 From: Anna Wilson Date: Fri, 24 Jun 2016 14:57:20 -0700 Subject: [PATCH 79/79] minor edits --- views/plain.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/views/plain.html b/views/plain.html index 74d0b5455..49fd8ea1b 100644 --- a/views/plain.html +++ b/views/plain.html @@ -70,7 +70,7 @@

          Rental

        • Look a movie up by id to see (/movies/rentals/2)

            -
          • it’s synopsis
          • +
          • its synopsis
          • release date
          • available inventory (not currently checked-out to a customer)
          • and inventory total
          • @@ -90,7 +90,8 @@

            Rental

          • “check in” one of customer’s rentals POST (/movies/rentals/:movie_id/return/:customer_id)
              -
            • return the movie to its inventory
            • +
            • Return the movie to its inventory
            • +
            • Change checked_out from true to false
          @@ -98,7 +99,7 @@

          Rental

        • See a list of customers with overdue movies (/movies/rentals/overdue)

            -
          • include customer name, movie title, check-out date, and return date
          • +
          • includes customer name, movie title, check-out date, and return date

          =================================

        • @@ -110,7 +111,7 @@

          Rental

        • (/customers/sort/:sort_params) (Some customers)
          • name : (/name?n=10&p=2) (sorted by name)
          • -
          • registered_at : (/registered-at?n=10&p=2) (sortedby join date)
          • +
          • registered_at : (/registered-at?n=10&p=2) (sorted by join date)
          • postal_code : (/postal-code?n=10&p=2) (sorted by location)
        • @@ -142,7 +143,7 @@

          [Rentals, an extension of Movies]

        • (/movies/rentals/:movie_id/customers) (Customers who currently have this movie checked out)
        • POST (/movies/rentals/:movie_id/checkout/:customer_id) (Creates a “check-out” of this movie to this customer, assigning the record a due date and charge)
        • POST (/movies/rentals/:movie_id/return/:customer_id) (“Returns” this movie checked out to this customer, changing checked-out status to false, and changing the available inventory accordingly)
        • -
        • (/movies/rentals/overdue)
        • +
        • (/movies/rentals/overdue)
        • (Customers with overdue movies)

        Informational endpoints