From 70739f7fdbdbc76a88441133659fe02752e1aea8 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 14:52:14 -0700 Subject: [PATCH 001/101] added scripts --- package.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d39b26403..0a1e59ae3 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:drop": "dropdb scrabble_express", + "db:create": "createdb scrabble_express", + "db:schema": "node tasks/load_schema.js", + "db:seed": "", + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" }, "dependencies": { "body-parser": "~1.13.2", From c3509565b42b0719289be9145a4dd2fe10e04b4a Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 14:52:34 -0700 Subject: [PATCH 002/101] added setup files --- db/setup/schema.sql | 8 ++++++++ db/setup/seed.sql | 0 2 files changed, 8 insertions(+) create mode 100644 db/setup/schema.sql create mode 100644 db/setup/seed.sql diff --git a/db/setup/schema.sql b/db/setup/schema.sql new file mode 100644 index 000000000..ee8981c11 --- /dev/null +++ b/db/setup/schema.sql @@ -0,0 +1,8 @@ +DROP TABLE IF EXISTS words; +CREATE TABLE words( + id serial PRIMARY KEY, + word text, + score integer +); + +CREATE INDEX words_word ON words (word); diff --git a/db/setup/seed.sql b/db/setup/seed.sql new file mode 100644 index 000000000..e69de29bb From 20cb8f8dfab4c4b1399da18f835879413afe0f1d Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 14:52:50 -0700 Subject: [PATCH 003/101] added load_schema file --- tasks/load_schema.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tasks/load_schema.js diff --git a/tasks/load_schema.js b/tasks/load_schema.js new file mode 100644 index 000000000..96155c1e6 --- /dev/null +++ b/tasks/load_schema.js @@ -0,0 +1,13 @@ +var massive = require('massive') +var connectionString = "postgres://localhost/scrabble_express" + +var db = massive.connectSync({connectionString : connectionString}) + +db.setup.schema([], function(err, res) { + if (err) { + throw(new Error(err.message)) + } + + console.log("yay schema!") + process.exit() +}) From ef62fa53004d030066b583e1349add46500aed01 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:02:34 -0700 Subject: [PATCH 004/101] made table for movies --- db/setup/schema.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index ee8981c11..a6466214c 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -1,8 +1,10 @@ -DROP TABLE IF EXISTS words; -CREATE TABLE words( - id serial PRIMARY KEY, - word text, - score integer +DROP TABLE IF EXISTS movies; +CREATE TABLE movies( + id PRIMARY KEY, + title text, + overview text, + release_date text, + inventory integer ); -CREATE INDEX words_word ON words (word); +CREATE INDEX movies_title ON movies (title); From e3075a30a90c0a65d21d74c445f8bff824e03f50 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:02:51 -0700 Subject: [PATCH 005/101] changed db name --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0a1e59ae3..5d3b7f7c0 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:drop": "dropdb scrabble_express", - "db:create": "createdb scrabble_express", + "db:drop": "dropdb cassetteconnection", + "db:create": "createdb cassetteconnection", "db:schema": "node tasks/load_schema.js", "db:seed": "", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" @@ -17,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 412e9854e6ac0354fdc044cdc25adde617dfe19c Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:03:07 -0700 Subject: [PATCH 006/101] changed db name --- tasks/load_schema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/load_schema.js b/tasks/load_schema.js index 96155c1e6..7e9466d4e 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,5 +1,5 @@ var massive = require('massive') -var connectionString = "postgres://localhost/scrabble_express" +var connectionString = "postgres://localhost/cassettecollection" var db = massive.connectSync({connectionString : connectionString}) From cd8b916b182c9312342e75106303f6f1a77b6822 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:22:29 -0700 Subject: [PATCH 007/101] created rentals join table and customer table --- db/setup/schema.sql | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index a6466214c..2d46772b4 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -1,6 +1,6 @@ DROP TABLE IF EXISTS movies; CREATE TABLE movies( - id PRIMARY KEY, + id integer PRIMARY KEY, title text, overview text, release_date text, @@ -8,3 +8,27 @@ CREATE TABLE movies( ); CREATE INDEX movies_title ON movies (title); + +DROP TABLE IF EXISTS customers; +CREATE TABLE customers( + id integer PRIMARY KEY, + name text, + registered_at text, + address text, + city text, + state text, + postal_code text, + phone text, + account_credit decimal +); + +CREATE INDEX customers_name ON customers (name); + +DROP TABLE IF EXISTS rentals; +CREATE TABLE rentals( + id integer PRIMARY KEY, + movie_id integer REFERENCES movies (id), + customer_id integer REFERENCES customers (id) +); + +CREATE INDEX rentals ON rentals (customer_id); From 623dd5764faabf70ae718868cbcdeb26367941af Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:29:45 -0700 Subject: [PATCH 008/101] created indexes --- db/setup/schema.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 2d46772b4..3bd590b76 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -8,6 +8,7 @@ CREATE TABLE movies( ); CREATE INDEX movies_title ON movies (title); +CREATE INDEX movies_date ON movies (release_date); DROP TABLE IF EXISTS customers; CREATE TABLE customers( @@ -23,12 +24,17 @@ CREATE TABLE customers( ); CREATE INDEX customers_name ON customers (name); +CREATE INDEX customers_date ON customers (registered_at); +CREATE INDEX customers_postal ON customers (postal_code); DROP TABLE IF EXISTS rentals; CREATE TABLE rentals( id integer PRIMARY KEY, movie_id integer REFERENCES movies (id), - customer_id integer REFERENCES customers (id) + customer_id integer REFERENCES customers (id), + status text, + checkout_date text, + return_date text ); CREATE INDEX rentals ON rentals (customer_id); From 40ab38ab2c41bbfd279a57b8a80d2e2b9fdcef5d Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:36:50 -0700 Subject: [PATCH 009/101] added indeces for rentals table --- db/setup/schema.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 3bd590b76..2100b17c2 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -38,3 +38,5 @@ CREATE TABLE rentals( ); CREATE INDEX rentals ON rentals (customer_id); +CREATE INDEX rentals_status ON rentals (status); + From 9d0f0ac7d8860555abbe0d6ea63921484bc77d5c Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:56:53 -0700 Subject: [PATCH 010/101] added controller files --- controllers/customers.js | 0 controllers/movies.js | 0 controllers/rentals.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 controllers/customers.js create mode 100644 controllers/movies.js create mode 100644 controllers/rentals.js diff --git a/controllers/customers.js b/controllers/customers.js new file mode 100644 index 000000000..e69de29bb diff --git a/controllers/movies.js b/controllers/movies.js new file mode 100644 index 000000000..e69de29bb diff --git a/controllers/rentals.js b/controllers/rentals.js new file mode 100644 index 000000000..e69de29bb From a03c7d69b22271ecace2b6d199e72adf9de5ab51 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:57:36 -0700 Subject: [PATCH 011/101] added files to routes --- routes/customers.js | 0 routes/movies.js | 0 routes/rentals.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 routes/customers.js create mode 100644 routes/movies.js create mode 100644 routes/rentals.js diff --git a/routes/customers.js b/routes/customers.js new file mode 100644 index 000000000..e69de29bb diff --git a/routes/movies.js b/routes/movies.js new file mode 100644 index 000000000..e69de29bb diff --git a/routes/rentals.js b/routes/rentals.js new file mode 100644 index 000000000..e69de29bb From 37067fff82016ffa9385fd24326eacd5f3366c9e Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 15:59:55 -0700 Subject: [PATCH 012/101] added files for routes --- routes/customers.js | 11 +++++++++++ routes/index.js | 2 ++ routes/movies.js | 11 +++++++++++ routes/rentals.js | 11 +++++++++++ 4 files changed, 35 insertions(+) diff --git a/routes/customers.js b/routes/customers.js index e69de29bb..3f198c60e 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -0,0 +1,11 @@ +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; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 06cfc1137..fabb00275 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,4 +6,6 @@ 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 index e69de29bb..3f198c60e 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -0,0 +1,11 @@ +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; \ No newline at end of file diff --git a/routes/rentals.js b/routes/rentals.js index e69de29bb..3f198c60e 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -0,0 +1,11 @@ +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; \ No newline at end of file From 01d209ad5cb403079786f47bd17733b3347c8834 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 16:00:14 -0700 Subject: [PATCH 013/101] defined routes for new route files --- app.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index f0579b1dc..1c0e18223 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,6 @@ var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); -var routes = require('./routes/index'); var app = express(); @@ -21,8 +20,19 @@ app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); + +var routes = require('./routes/index'); app.use('/', routes); +var moviesRoutes = require('./routes/movies'); +app.use('/movies', moviesRoutes); + +var customersRoutes = require('./routes/customers'); +app.use('/customers', customersRoutes); + +var rentalsRoutes = require('./routes/rentals'); +app.use('/rentals', rentalsRoutes); + // catch 404 and forward to error handler app.use(function(req, res, next) { var err = new Error('Not Found'); From b201316d08d5c0df37bafb811a62deec19a4c028 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 17:11:07 -0700 Subject: [PATCH 014/101] add script for seed --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5d3b7f7c0..b64eeabee 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "scripts": { "start": "nodemon ./bin/www", "test": "clear; jasmine-node --verbose spec/", - "db:drop": "dropdb cassetteconnection", - "db:create": "createdb cassetteconnection", + "db:drop": "dropdb cassettecollection", + "db:create": "createdb cassettecollection", "db:schema": "node tasks/load_schema.js", - "db:seed": "", + "db:seed": "node tasks/seed_data.js", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" }, "dependencies": { From 8c8abc97bf7b8ee0d35a798263d9e183b640a8bb Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 17:11:30 -0700 Subject: [PATCH 015/101] added serial to primary key --- db/setup/schema.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index 2100b17c2..b0b1f38fb 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -1,6 +1,6 @@ DROP TABLE IF EXISTS movies; CREATE TABLE movies( - id integer PRIMARY KEY, + id serial PRIMARY KEY, title text, overview text, release_date text, @@ -12,7 +12,7 @@ CREATE INDEX movies_date ON movies (release_date); DROP TABLE IF EXISTS customers; CREATE TABLE customers( - id integer PRIMARY KEY, + id serial PRIMARY KEY, name text, registered_at text, address text, @@ -29,7 +29,7 @@ CREATE INDEX customers_postal ON customers (postal_code); DROP TABLE IF EXISTS rentals; CREATE TABLE rentals( - id integer PRIMARY KEY, + id serial PRIMARY KEY, movie_id integer REFERENCES movies (id), customer_id integer REFERENCES customers (id), status text, @@ -37,6 +37,6 @@ CREATE TABLE rentals( return_date text ); -CREATE INDEX rentals ON rentals (customer_id); +CREATE INDEX rentals_customers ON rentals (customer_id); CREATE INDEX rentals_status ON rentals (status); From 3c4a02279af60b0306dd87ff95fe6c3fe497b602 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 17:12:21 -0700 Subject: [PATCH 016/101] zomg --- routes/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routes/index.js b/routes/index.js index fabb00275..21b4f7e34 100644 --- a/routes/index.js +++ b/routes/index.js @@ -6,6 +6,10 @@ router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) }); +router.get('/zomg', function(req, res, next) { + res.status(200).json({message: 'it works!'}) +}); + module.exports = router; From 3ebced87cfdfcd26b7634f475127b74e14ed1f7e Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Tue, 14 Jun 2016 17:13:18 -0700 Subject: [PATCH 017/101] created loop for movie table seeding --- tasks/seed_data.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tasks/seed_data.js diff --git a/tasks/seed_data.js b/tasks/seed_data.js new file mode 100644 index 000000000..75c3a9713 --- /dev/null +++ b/tasks/seed_data.js @@ -0,0 +1,16 @@ +var massive = require('massive') +var connectionString = "postgres://localhost/cassettecollection" + +var db = massive.connectSync({connectionString : connectionString}) +var movies_data = require("../db/seeds/movies") +// var movies_array = JSON.parse(movies_data) +console.log(movies_data) + +for(var movie of movies_data){ + db.movies.save({title: movie.title, overview: movie.overview, release_date: movie.release_date, inventory: movie.inventory}, function(err,res){ + if(err) { + throw new Error(err.message) + } + }) +} + From a0e724f841dbc74058e3910fac11822dbd66e931 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 10:10:48 -0700 Subject: [PATCH 018/101] Update rentals schema to use due_date instead or return_date; --- db/setup/schema.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/setup/schema.sql b/db/setup/schema.sql index b0b1f38fb..2542773be 100644 --- a/db/setup/schema.sql +++ b/db/setup/schema.sql @@ -34,9 +34,8 @@ CREATE TABLE rentals( customer_id integer REFERENCES customers (id), status text, checkout_date text, - return_date text + due_date text ); CREATE INDEX rentals_customers ON rentals (customer_id); CREATE INDEX rentals_status ON rentals (status); - From 9a4df2e846cd47e024ac2a9976f417cca667f728 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 10:12:35 -0700 Subject: [PATCH 019/101] add seed data for rentals table; --- 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..da7209e26 --- /dev/null +++ b/db/seeds/rentals.json @@ -0,0 +1,23 @@ +[ +{ +"movie_id": 2, +"customer_id": 4, +"status": "checked_out", +"checkout_date": "2016-06-14", +"due_date": "2016-06-24" +}, +{ +"movie_id": 33, +"customer_id": 55, +"status": "overdue", +"checkout_date": "1960-06-03", +"due_date": "1960-06-13" +}, +{ +"movie_id": 1, +"customer_id": 3, +"status": "returned", +"checkout_date": "2016-06-02", +"due_date": "2016-06-12" +} +] From c0acf6f894e84f5ffecf2fc85989ffee21ae4d3d Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 10:13:16 -0700 Subject: [PATCH 020/101] Add seed rentals loop to seed task; --- tasks/seed_data.js | 48 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/tasks/seed_data.js b/tasks/seed_data.js index 75c3a9713..1afcd76c1 100644 --- a/tasks/seed_data.js +++ b/tasks/seed_data.js @@ -3,14 +3,48 @@ var connectionString = "postgres://localhost/cassettecollection" var db = massive.connectSync({connectionString : connectionString}) var movies_data = require("../db/seeds/movies") -// var movies_array = JSON.parse(movies_data) -console.log(movies_data) +var customers_data = require("../db/seeds/customers") +var rentals_data = require("../db/seeds/rentals") -for(var movie of movies_data){ - db.movies.save({title: movie.title, overview: movie.overview, release_date: movie.release_date, inventory: movie.inventory}, function(err,res){ - if(err) { - throw new Error(err.message) + +function seed() { + var seeded_movies = 0 + var seeded_customers = 0 + var seeded_rentals = 0 + + // while (seeded_customers !== customers_data.length && seeded_movies !== movies_data.length) { + for (var movie of movies_data) { + db.movies.save({title: movie.title, overview: movie.overview, release_date: movie.release_date, inventory: movie.inventory}, function (err,res) { + if (err) { + throw new Error(err.message) + } + seeded_movies++ + }) + } + + for (var customer of customers_data) { + db.customers.save({name: customer.name, registered_at: customer.registered_at, address: customer.address, city: customer.city, state: customer.state, postal_code: customer.postal_code, phone: customer.phone, account_credit: customer.account_credit}, function (err,res) { + if (err) { + throw new Error(err.message) + } + seeded_customers++ + // console.log(res) + }) } - }) + + for (var rental of rentals_data) { + db.rentals.save({movie_id: rental.movie_id, customer_id: rental.customer_id, status: rental.status, checkout_date: rental.checkout_date, due_date: rental.due_date }, function (err,res) { + if (err) { + throw new Error(err.message) + } + seeded_rentals++ + // console.log(res) + }) + } + // } + + // process.exit() } +seed() +// seed(null, process.exit()) From f84a4a1826807f04b0659f5b99a9dfc4e8fda1b8 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 10:13:58 -0700 Subject: [PATCH 021/101] npm debug log; --- 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..fc1cd362d --- /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/sophia/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/sophia/.rvm/gems/ruby-2.3.0/bin:/Users/sophia/.rvm/gems/ruby-2.3.0@global/bin:/Users/sophia/.rvm/rubies/ruby-2.3.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/sophia/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~db:seed: CWD: /Users/sophia/C5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~db:seed: Args: [ '-c', 'node tasks/seed_data.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: `node tasks/seed_data.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/sophia/C5/projects/VideoStoreAPI +17 error Darwin 13.4.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: `node tasks/seed_data.js` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 db:seed script 'node tasks/seed_data.js'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the video-store-api package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error node tasks/seed_data.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 dddeb2bac5fd67cb83a72fbe62c02b3193f53512 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 13:45:26 -0700 Subject: [PATCH 022/101] Placeholder routes; --- routes/customers.js | 11 ++++++----- routes/movies.js | 12 ++++++------ routes/rentals.js | 13 +++++++------ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/routes/customers.js b/routes/customers.js index 3f198c60e..3397d0771 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -1,11 +1,12 @@ var express = require('express'); var router = express.Router(); +var customersController = require('../controllers/customers') -/* GET home page. */ -router.get('/', function(req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) -}); +router.get('/', customersController.index) // nothing here, probably omit +router.get('/customers/sort/:query', customersController.sortBy(parmas.req.query)) +router.get('/customers/:num/current', customersController.current) +router.get('/customers/:num/history', customersController.history) -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/routes/movies.js b/routes/movies.js index 3f198c60e..ab0a53424 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -1,11 +1,11 @@ var express = require('express'); var router = express.Router(); +var moviesController = require('../controllers/movies') -/* GET home page. */ -router.get('/', function(req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) -}); +router.get('/', moviesController.listMovies) +router.get('/sort/:query', moviesController.sortBy) +router.get('/:movie/current', moviesController.current) +router.get('/:movie/history/sort/:by', moviesController.sortedHistory) - -module.exports = router; \ No newline at end of file +module.exports = router; diff --git a/routes/rentals.js b/routes/rentals.js index 3f198c60e..508a392ca 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -1,11 +1,12 @@ var express = require('express'); var router = express.Router(); +var rentalsController = require('../controllers/rentals') -/* GET home page. */ -router.get('/', function(req, res, next) { - res.status(200).json({whatevs: 'whatevs!!!'}) -}); +router.get('/:movie', rentalsController.lookupMovie) +router.get('/:movie/customers', rentalsController.sortBy) // do we need to pass stuff in? +router.post('/:movie/check-out', rentalsController.checkOut) // requires json data customer_id and movie title +router.post('/:movie/return', rentalsController.return) // requires json data customer_id and movie title +router.get('/overdue', rentalsController.overdue) - -module.exports = router; \ No newline at end of file +module.exports = router; From 530759d0526162a796ada0acdf5d54b4de419ae5 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 15:43:49 -0700 Subject: [PATCH 023/101] Fix seed task so that it ends the process when all data is seeded; --- npm-debug.log | 48 ---------------------------------------------- tasks/seed_data.js | 35 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index fc1cd362d..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/sophia/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/sophia/.rvm/gems/ruby-2.3.0/bin:/Users/sophia/.rvm/gems/ruby-2.3.0@global/bin:/Users/sophia/.rvm/rubies/ruby-2.3.0/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/sophia/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~db:seed: CWD: /Users/sophia/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~db:seed: Args: [ '-c', 'node tasks/seed_data.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: `node tasks/seed_data.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/sophia/C5/projects/VideoStoreAPI -17 error Darwin 13.4.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: `node tasks/seed_data.js` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 db:seed script 'node tasks/seed_data.js'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the video-store-api package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error node tasks/seed_data.js -23 error You can get information on how to open an issue for this project with: -23 error npm bugs video-store-api -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls video-store-api -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/tasks/seed_data.js b/tasks/seed_data.js index 1afcd76c1..a054a274e 100644 --- a/tasks/seed_data.js +++ b/tasks/seed_data.js @@ -6,45 +6,52 @@ var movies_data = require("../db/seeds/movies") var customers_data = require("../db/seeds/customers") var rentals_data = require("../db/seeds/rentals") +var moviesCount = 0 +var customersCount = 0 +var rentalsCount = 0 function seed() { - var seeded_movies = 0 - var seeded_customers = 0 - var seeded_rentals = 0 - + // saveSync is not asynchronous, it's blocking, ok for stuff like this that is run every once in a while // while (seeded_customers !== customers_data.length && seeded_movies !== movies_data.length) { for (var movie of movies_data) { - db.movies.save({title: movie.title, overview: movie.overview, release_date: movie.release_date, inventory: movie.inventory}, function (err,res) { + db.movies.save(movie, function (err,res) { if (err) { throw new Error(err.message) } - seeded_movies++ + moviesCount++ + checkFinish() }) } for (var customer of customers_data) { - db.customers.save({name: customer.name, registered_at: customer.registered_at, address: customer.address, city: customer.city, state: customer.state, postal_code: customer.postal_code, phone: customer.phone, account_credit: customer.account_credit}, function (err,res) { + db.customers.save(customer, function (err,res) { if (err) { throw new Error(err.message) } - seeded_customers++ - // console.log(res) + customersCount++ + checkFinish() }) } for (var rental of rentals_data) { - db.rentals.save({movie_id: rental.movie_id, customer_id: rental.customer_id, status: rental.status, checkout_date: rental.checkout_date, due_date: rental.due_date }, function (err,res) { + db.rentals.save(rental, function (err,res) { if (err) { throw new Error(err.message) } - seeded_rentals++ - // console.log(res) + rentalsCount++ + checkFinish() }) } // } +} + +function checkFinish() { + var totalCount = moviesCount + customersCount + rentalsCount + var totalLength = movies_data.length + customers_data.length + rentals_data.length - // process.exit() + // console.log("total count", totalCount) + // console.log(totalCount >= totalLength) + if (totalCount >= totalLength) { process.exit() } } seed() -// seed(null, process.exit()) From 108f85ec90975511e14fee23de7f167a9d25d1ac Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 15:45:01 -0700 Subject: [PATCH 024/101] clean up seeding task; --- tasks/seed_data.js | 62 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/tasks/seed_data.js b/tasks/seed_data.js index a054a274e..bf5480745 100644 --- a/tasks/seed_data.js +++ b/tasks/seed_data.js @@ -12,45 +12,41 @@ var rentalsCount = 0 function seed() { // saveSync is not asynchronous, it's blocking, ok for stuff like this that is run every once in a while - // while (seeded_customers !== customers_data.length && seeded_movies !== movies_data.length) { - for (var movie of movies_data) { - db.movies.save(movie, function (err,res) { - if (err) { - throw new Error(err.message) - } - moviesCount++ - checkFinish() - }) - } - - for (var customer of customers_data) { - db.customers.save(customer, function (err,res) { - if (err) { - throw new Error(err.message) - } - customersCount++ - checkFinish() - }) - } - - for (var rental of rentals_data) { - db.rentals.save(rental, function (err,res) { - if (err) { - throw new Error(err.message) - } - rentalsCount++ - checkFinish() - }) - } - // } + for (var movie of movies_data) { + db.movies.save(movie, function (err,res) { + if (err) { + throw new Error(err.message) + } + moviesCount++ + checkFinish() + }) + } + + for (var customer of customers_data) { + db.customers.save(customer, function (err,res) { + if (err) { + throw new Error(err.message) + } + customersCount++ + checkFinish() + }) + } + + for (var rental of rentals_data) { + db.rentals.save(rental, function (err,res) { + if (err) { + throw new Error(err.message) + } + rentalsCount++ + checkFinish() + }) + } } function checkFinish() { var totalCount = moviesCount + customersCount + rentalsCount var totalLength = movies_data.length + customers_data.length + rentals_data.length - // console.log("total count", totalCount) - // console.log(totalCount >= totalLength) if (totalCount >= totalLength) { process.exit() } } From 8a178dcce7e1ea274f50059962f35f76292205ab Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 18:34:15 -0700 Subject: [PATCH 025/101] Capitalize controller names; --- routes/customers.js | 12 +++++------- routes/movies.js | 10 +++++----- routes/rentals.js | 13 ++++++------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/routes/customers.js b/routes/customers.js index 3397d0771..105795c28 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -1,12 +1,10 @@ var express = require('express'); var router = express.Router(); -var customersController = require('../controllers/customers') - -router.get('/', customersController.index) // nothing here, probably omit -router.get('/customers/sort/:query', customersController.sortBy(parmas.req.query)) -router.get('/customers/:num/current', customersController.current) -router.get('/customers/:num/history', customersController.history) - +var CustomersController = require('../controllers/customers') +router.get('/', CustomersController.index) // nothing here, probably omit +router.get('/customers/sort/:query', CustomersController.sortBy(parmas.req.query)) +router.get('/customers/:num/current', CustomersController.current) +router.get('/customers/:num/history', CustomersController.history) module.exports = router; diff --git a/routes/movies.js b/routes/movies.js index ab0a53424..cdefac322 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -1,11 +1,11 @@ var express = require('express'); var router = express.Router(); -var moviesController = require('../controllers/movies') +var MoviesController = require('../controllers/movies') -router.get('/', moviesController.listMovies) -router.get('/sort/:query', moviesController.sortBy) -router.get('/:movie/current', moviesController.current) -router.get('/:movie/history/sort/:by', moviesController.sortedHistory) +router.get('/', MoviesController.listMovies) +router.get('/sort/:query', MoviesController.sortBy) +router.get('/:movie/current', MoviesController.current) +router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) module.exports = router; diff --git a/routes/rentals.js b/routes/rentals.js index 508a392ca..422905c03 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -1,12 +1,11 @@ var express = require('express'); var router = express.Router(); -var rentalsController = require('../controllers/rentals') - -router.get('/:movie', rentalsController.lookupMovie) -router.get('/:movie/customers', rentalsController.sortBy) // do we need to pass stuff in? -router.post('/:movie/check-out', rentalsController.checkOut) // requires json data customer_id and movie title -router.post('/:movie/return', rentalsController.return) // requires json data customer_id and movie title -router.get('/overdue', rentalsController.overdue) +var RentalsController = require('../controllers/rentals') +router.get('/:movie', RentalsController.lookupMovie) +router.get('/:movie/customers', RentalsController.sortBy) // do we need to pass stuff in? +router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title +router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title +router.get('/overdue', RentalsController.overdue) module.exports = router; From 2532a2a4801a871ce7da1aa4ded22b42ad0e00ae Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 15 Jun 2016 18:34:48 -0700 Subject: [PATCH 026/101] Setup skeleton for controllers with functions; --- controllers/customers.js | 20 ++++++++++++++++++++ controllers/movies.js | 20 ++++++++++++++++++++ controllers/rentals.js | 24 ++++++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/controllers/customers.js b/controllers/customers.js index e69de29bb..eefac2822 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -0,0 +1,20 @@ +var CustomersController = { + + function index() { + + }, + + function sortBy() { + + }, + + function current() { + + }, + + function history() { + + } +} + +modules.exports = CustomersController diff --git a/controllers/movies.js b/controllers/movies.js index e69de29bb..73350a206 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -0,0 +1,20 @@ +var MoviesController = { + + function listMovies () { + + }, + + function sortBy () { + + }, + + function current () { + + }, + + function sortedHistory () { + + } +} + +modules.exports = MoviesController diff --git a/controllers/rentals.js b/controllers/rentals.js index e69de29bb..79d19aca1 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -0,0 +1,24 @@ +var RentalsController = { + + function lookupMovie () { + + }, + + function sortBy () { + + }, + + function checkOut () { + + }, + + function return () { + + }, + + function overdue () { + + } +} + +modules.exports = RentalsController From 248205f6acf600e320854befb8b96c0670913fcb Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 16 Jun 2016 14:03:39 -0700 Subject: [PATCH 027/101] Fix customer routes so it doesn't say customers because that's specified in app.js; --- routes/customers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/customers.js b/routes/customers.js index 105795c28..43552ed9a 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -3,8 +3,8 @@ var router = express.Router(); var CustomersController = require('../controllers/customers') router.get('/', CustomersController.index) // nothing here, probably omit -router.get('/customers/sort/:query', CustomersController.sortBy(parmas.req.query)) -router.get('/customers/:num/current', CustomersController.current) -router.get('/customers/:num/history', CustomersController.history) +router.get('/sort/:query', CustomersController.sortBy(parmas.req.query)) +router.get('/:id/current', CustomersController.current) +router.get('/:id/history', CustomersController.history) module.exports = router; From e2f79975d01b8e08b83724bbfb0f3aff715dde17 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 14:11:17 -0700 Subject: [PATCH 028/101] made model files and added customer.all --- models/customer.js | 22 ++++++++++++++++++++++ models/movie.js | 0 models/rental.js | 0 3 files changed, 22 insertions(+) create mode 100644 models/customer.js create mode 100644 models/movie.js create mode 100644 models/rental.js diff --git a/models/customer.js b/models/customer.js new file mode 100644 index 000000000..87ad21e82 --- /dev/null +++ b/models/customer.js @@ -0,0 +1,22 @@ +var app = require("../app"); +var db = app.get("db"); + +// Constructor function +var Customer = function(id) { + this.id = id; +}; + + +Customer.all = function(callback) { + db.customers.run(function(error, customers) { + if(error || !customers) { + callback(error || new Error("Could not retrieve Customers"), undefined); + } else { + callback(null, customers.map(function(Customer) { + return new Customer(customers.id); + })); + } + }); +}; + +module.exports = Customer \ No newline at end of file diff --git a/models/movie.js b/models/movie.js new file mode 100644 index 000000000..e69de29bb diff --git a/models/rental.js b/models/rental.js new file mode 100644 index 000000000..e69de29bb From 375f1da71a8f527b223c3619c4c28490a112970b Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 14:15:06 -0700 Subject: [PATCH 029/101] added index function --- controllers/customers.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index eefac2822..347a1dbcf 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -1,7 +1,19 @@ -var CustomersController = { - - function index() { +var Customer = require("../models/customer") +var CustomersController = { + index: function(req, res, next) { + Customer.all(function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers) + // res.render("accounts/index", { + // accounts: accounts + // }); + } + }); }, function sortBy() { From 89c65c95688ec33b96dae059193badf84184c38f Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 14:15:20 -0700 Subject: [PATCH 030/101] change db query --- models/customer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/customer.js b/models/customer.js index 87ad21e82..1f214174f 100644 --- a/models/customer.js +++ b/models/customer.js @@ -8,7 +8,7 @@ var Customer = function(id) { Customer.all = function(callback) { - db.customers.run(function(error, customers) { + db.run("SELECT * FROM customers;", function(error, customers) { if(error || !customers) { callback(error || new Error("Could not retrieve Customers"), undefined); } else { From 081725a350ee98ce252f44fe78aa94a0ac2a8f28 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 14:17:44 -0700 Subject: [PATCH 031/101] fix typo --- routes/customers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/customers.js b/routes/customers.js index 43552ed9a..78804c802 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -3,7 +3,7 @@ var router = express.Router(); var CustomersController = require('../controllers/customers') router.get('/', CustomersController.index) // nothing here, probably omit -router.get('/sort/:query', CustomersController.sortBy(parmas.req.query)) +router.get('/sort/:query', CustomersController.sortBy(params.req.query)) router.get('/:id/current', CustomersController.current) router.get('/:id/history', CustomersController.history) From 8151f8a367fbdd2f2c8e2db291e104bb00b80d30 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 15:31:47 -0700 Subject: [PATCH 032/101] initialize db --- app.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 1c0e18223..b1c7ad2a6 100644 --- a/app.js +++ b/app.js @@ -5,9 +5,13 @@ var logger = require('morgan'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); +var massive = require('massive') var app = express(); - +module.exports = app; +var connectionString = "postgres://localhost/cassettecollection" +var db = massive.connectSync({connectionString : connectionString}) +app.set("db", db) // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); @@ -24,14 +28,14 @@ app.use(express.static(path.join(__dirname, 'public'))); var routes = require('./routes/index'); app.use('/', routes); -var moviesRoutes = require('./routes/movies'); -app.use('/movies', moviesRoutes); +// var moviesRoutes = require('./routes/movies'); +// app.use('/movies', moviesRoutes); var customersRoutes = require('./routes/customers'); app.use('/customers', customersRoutes); -var rentalsRoutes = require('./routes/rentals'); -app.use('/rentals', rentalsRoutes); +// var rentalsRoutes = require('./routes/rentals'); +// app.use('/rentals', rentalsRoutes); // catch 404 and forward to error handler app.use(function(req, res, next) { From e62b4ae65911f90429b76cccb3d74ea139c55879 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 15:32:12 -0700 Subject: [PATCH 033/101] finished sortby and index function for customers --- controllers/customers.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 347a1dbcf..e2cf01d5c 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -3,6 +3,23 @@ var Customer = require("../models/customer") var CustomersController = { index: function(req, res, next) { Customer.all(function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers) + } + }); + }, + + sortBy: function(req, res, next) { + console.log("bla",req.params.query, req.query.n, req.query.p) + var n = req.query.n + var p = req.query.p + var firstrow = n*(p-1)+1 + var lastrow = n*p + Customer.sortByName([firstrow,lastrow],function(error, customers) { if(error) { var err = new Error("Error retrieving customer list:\n" + error.message); err.status = 500; @@ -14,19 +31,15 @@ var CustomersController = { // }); } }); - }, - - function sortBy() { - - }, + } - function current() { + // function current() { - }, + // }, - function history() { + // function history() { - } + // } } -modules.exports = CustomersController +module.exports = CustomersController From 463fe95ff2e527cb0a8afdcc5351b9c1e3f84d07 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 15:32:30 -0700 Subject: [PATCH 034/101] added seed to db:reset --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b64eeabee..a25be8949 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "db:create": "createdb cassettecollection", "db:schema": "node tasks/load_schema.js", "db:seed": "node tasks/seed_data.js", - "db:reset": "npm run db:drop; npm run db:create; npm run db:schema" + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" }, "dependencies": { "body-parser": "~1.13.2", From 752355941a48d2f1adba34931a67f36fc56c63e6 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 15:32:47 -0700 Subject: [PATCH 035/101] ignoring some lines --- routes/customers.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/routes/customers.js b/routes/customers.js index 78804c802..5dd16b49d 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -3,8 +3,8 @@ var router = express.Router(); var CustomersController = require('../controllers/customers') router.get('/', CustomersController.index) // nothing here, probably omit -router.get('/sort/:query', CustomersController.sortBy(params.req.query)) -router.get('/:id/current', CustomersController.current) -router.get('/:id/history', CustomersController.history) +router.get('/sort/:query', CustomersController.sortBy) +// router.get('/:id/current', CustomersController.current) +// router.get('/:id/history', CustomersController.history) module.exports = router; From 3e69ff878b80baad45dae3989f2d5fab9d862076 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 15:32:58 -0700 Subject: [PATCH 036/101] ignoring some line pt 2 --- routes/movies.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/routes/movies.js b/routes/movies.js index cdefac322..63e549d73 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -1,11 +1,11 @@ -var express = require('express'); -var router = express.Router(); -var MoviesController = require('../controllers/movies') +// var express = require('express'); +// var router = express.Router(); +// var MoviesController = require('../controllers/movies') -router.get('/', MoviesController.listMovies) -router.get('/sort/:query', MoviesController.sortBy) -router.get('/:movie/current', MoviesController.current) -router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) +// router.get('/', MoviesController.listMovies) +// router.get('/sort/:query', MoviesController.sortBy) +// router.get('/:movie/current', MoviesController.current) +// router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) -module.exports = router; +// module.exports = router; From b5ef86647dc58de68b6ffa75f3e5923ed16df5f1 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 15:33:21 -0700 Subject: [PATCH 037/101] created sortbyname function --- models/customer.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/models/customer.js b/models/customer.js index 1f214174f..5a9240d31 100644 --- a/models/customer.js +++ b/models/customer.js @@ -2,8 +2,9 @@ var app = require("../app"); var db = app.get("db"); // Constructor function -var Customer = function(id) { - this.id = id; +var Customer = function(customer) { + this.id = customer.id; + this.name = customer.name; }; @@ -12,11 +13,22 @@ Customer.all = function(callback) { if(error || !customers) { callback(error || new Error("Could not retrieve Customers"), undefined); } else { - callback(null, customers.map(function(Customer) { - return new Customer(customers.id); + callback(null, customers.map(function(customer) { + return new Customer(customer); })); } }); }; +Customer.sortByName = function(input, callback){ + db.run("Select * From (Select Row_Number() Over (Order By name) As RowNum, *From customers) customers Where RowNum BETWEEN $1 AND $2;",input, function(error, customers) { + if(error || !customers) { + callback(error || new Error("Could not retrieve Customers"), undefined); + } else { + callback(null, customers.map(function(customer) { + return new Customer(customer); + })); + } + }); +}; module.exports = Customer \ No newline at end of file From 131c8373220fcc48a0921a0a31187edbe41e70ad Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 16:03:18 -0700 Subject: [PATCH 038/101] enable movie routes --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index b1c7ad2a6..c1175eb5d 100644 --- a/app.js +++ b/app.js @@ -28,8 +28,8 @@ app.use(express.static(path.join(__dirname, 'public'))); var routes = require('./routes/index'); app.use('/', routes); -// var moviesRoutes = require('./routes/movies'); -// app.use('/movies', moviesRoutes); +var moviesRoutes = require('./routes/movies'); +app.use('/movies', moviesRoutes); var customersRoutes = require('./routes/customers'); app.use('/customers', customersRoutes); From 07215f65150168bfa980bf39ec2b2610c240d379 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 16:03:34 -0700 Subject: [PATCH 039/101] made index function for movies --- controllers/movies.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 73350a206..35bc8a431 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -1,20 +1,29 @@ -var MoviesController = { - - function listMovies () { +var Movie = require("../models/movie") - }, +var MoviesController = { + index: function(req, res, next) { + Movie.all(function(error, movies) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(movies) + } + }); + } - function sortBy () { + // function sortBy () { - }, + // }, - function current () { + // function current () { - }, + // }, - function sortedHistory () { + // function sortedHistory () { - } + // } } -modules.exports = MoviesController +module.exports = MoviesController From c30a4aa03e6169eeec54b5c5905205fd3a592c08 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 16 Jun 2016 16:54:28 -0700 Subject: [PATCH 040/101] finished all sortbys for customer --- controllers/customers.js | 5 +++-- models/customer.js | 7 +++++-- models/movie.js | 23 +++++++++++++++++++++++ routes/movies.js | 10 +++++----- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index e2cf01d5c..fc339d7cd 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -14,12 +14,13 @@ var CustomersController = { }, sortBy: function(req, res, next) { - console.log("bla",req.params.query, req.query.n, req.query.p) + var type = req.params.query var n = req.query.n var p = req.query.p var firstrow = n*(p-1)+1 var lastrow = n*p - Customer.sortByName([firstrow,lastrow],function(error, customers) { + console.log("bla",type,firstrow,lastrow) + Customer.sortBy([type,firstrow,lastrow],function(error, customers) { if(error) { var err = new Error("Error retrieving customer list:\n" + error.message); err.status = 500; diff --git a/models/customer.js b/models/customer.js index 5a9240d31..29ac45579 100644 --- a/models/customer.js +++ b/models/customer.js @@ -5,6 +5,8 @@ var db = app.get("db"); var Customer = function(customer) { this.id = customer.id; this.name = customer.name; + this.registered_at = customer.registered_at; + this.postal_code = customer.postal_code }; @@ -20,8 +22,9 @@ Customer.all = function(callback) { }); }; -Customer.sortByName = function(input, callback){ - db.run("Select * From (Select Row_Number() Over (Order By name) As RowNum, *From customers) customers Where RowNum BETWEEN $1 AND $2;",input, function(error, customers) { +Customer.sortBy = function(input, callback){ + var order = input.shift() + db.run("Select * From (Select Row_Number() Over (Order By " + order + ") As RowNum, *From customers) customers Where RowNum BETWEEN $1 AND $2;",input, function(error, customers) { if(error || !customers) { callback(error || new Error("Could not retrieve Customers"), undefined); } else { diff --git a/models/movie.js b/models/movie.js index e69de29bb..e56dc2a81 100644 --- a/models/movie.js +++ b/models/movie.js @@ -0,0 +1,23 @@ +var app = require("../app"); +var db = app.get("db"); + +// Constructor function +var Movie = function(movie) { + this.id = movie.id; + this.title = movie.title; +}; + + +Movie.all = function(callback) { + db.run("SELECT * FROM movies;", function(error, movies) { + if(error || !movies) { + callback(error || new Error("Could not retrieve movies"), undefined); + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie); + })); + } + }); +}; + +module.exports = Movie \ No newline at end of file diff --git a/routes/movies.js b/routes/movies.js index 63e549d73..4b5f32eee 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -1,11 +1,11 @@ -// var express = require('express'); -// var router = express.Router(); -// var MoviesController = require('../controllers/movies') +var express = require('express'); +var router = express.Router(); +var MoviesController = require('../controllers/movies') -// router.get('/', MoviesController.listMovies) +router.get('/', MoviesController.index) // router.get('/sort/:query', MoviesController.sortBy) // router.get('/:movie/current', MoviesController.current) // router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) -// module.exports = router; +module.exports = router; From 8210c54508deb712405d0a6923e87fc6683484da Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 09:45:05 -0700 Subject: [PATCH 041/101] added sortby method --- controllers/movies.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 35bc8a431..d642f8a90 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -11,11 +11,24 @@ var MoviesController = { res.json(movies) } }); - } - - // function sortBy () { - - // }, + }, + + sortBy: function(req, res, next) { + var type = req.params.query + var n = req.query.n + var p = req.query.p + var firstrow = n*(p-1)+1 + var lastrow = n*p + console.log("bla",type,firstrow,lastrow) + Movie.sortBy([type,firstrow,lastrow],function(error, movies) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(movies) + } + })} // function current () { From 55590cb837ed302449a58efe32f18d76f99b606b Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 09:45:29 -0700 Subject: [PATCH 042/101] added sortby method --- models/movie.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/models/movie.js b/models/movie.js index e56dc2a81..698d2be67 100644 --- a/models/movie.js +++ b/models/movie.js @@ -5,6 +5,7 @@ var db = app.get("db"); var Movie = function(movie) { this.id = movie.id; this.title = movie.title; + this.release = movie.release_date; }; @@ -20,4 +21,17 @@ Movie.all = function(callback) { }); }; +Movie.sortBy = function(input, callback){ + var order = input.shift() + db.run("Select * From (Select Row_Number() Over (Order By " + order + ") As RowNum, *From movies) movies Where RowNum BETWEEN $1 AND $2;",input, function(error, movies) { + if(error || !movies) { + callback(error || new Error("Could not retrieve Movies"), undefined); + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie); + })); + } + }); +}; + module.exports = Movie \ No newline at end of file From c86f1f58fbc34b79174447940bd319b177aed640 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 09:45:52 -0700 Subject: [PATCH 043/101] uncommented sort route --- routes/movies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/movies.js b/routes/movies.js index 4b5f32eee..8596aeffe 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -3,7 +3,7 @@ var router = express.Router(); var MoviesController = require('../controllers/movies') router.get('/', MoviesController.index) -// router.get('/sort/:query', MoviesController.sortBy) +router.get('/sort/:query', MoviesController.sortBy) // router.get('/:movie/current', MoviesController.current) // router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) From 5c6fcbde44f012d1fc84a655b9c07434f035423b Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 09:46:05 -0700 Subject: [PATCH 044/101] deleted comments --- controllers/customers.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index fc339d7cd..8411eeb20 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -27,9 +27,6 @@ var CustomersController = { next(err); } else { res.json(customers) - // res.render("accounts/index", { - // accounts: accounts - // }); } }); } From c9bdf3f15a98ba18394b3d5a498fc30c2a463707 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 11:08:12 -0700 Subject: [PATCH 045/101] working on current function --- controllers/customers.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 8411eeb20..c58f09403 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -1,4 +1,5 @@ var Customer = require("../models/customer") +var Rental = require('../models/rental') var CustomersController = { index: function(req, res, next) { @@ -29,15 +30,33 @@ var CustomersController = { res.json(customers) } }); - } - - // function current() { - - // }, + }, - // function history() { + current: function(req, res, next) { + var id = req.params.id + Rental.rentals(["checked_out", id], function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers) + } + }); + } - // } + history: function(req, res, next) { + var id = req.params.id + Rental.rentals(["returned", id], function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers) + } + }); + } } module.exports = CustomersController From a66e099072140421357e1338004ae7826bec0f0d Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 11:08:27 -0700 Subject: [PATCH 046/101] added more records to rental seed --- db/seeds/rentals.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json index da7209e26..a27b71ed8 100644 --- a/db/seeds/rentals.json +++ b/db/seeds/rentals.json @@ -7,6 +7,20 @@ "due_date": "2016-06-24" }, { +"movie_id": 4, +"customer_id": 4, +"status": "returned", +"checkout_date": "1960-06-03", +"due_date": "1960-06-13" +}, +{ +"movie_id": 1, +"customer_id": 4, +"status": "checked_out", +"checkout_date": "2016-06-03", +"due_date": "2017-06-13" +}, +{ "movie_id": 33, "customer_id": 55, "status": "overdue", From 36b8ca69962194deb40c249538139c19521b1a10 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 11:08:52 -0700 Subject: [PATCH 047/101] moved function from customer to rental --- models/customer.js | 5 ++++- models/rental.js | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/models/customer.js b/models/customer.js index 29ac45579..fbf2359bf 100644 --- a/models/customer.js +++ b/models/customer.js @@ -6,7 +6,7 @@ var Customer = function(customer) { this.id = customer.id; this.name = customer.name; this.registered_at = customer.registered_at; - this.postal_code = customer.postal_code + this.postal_code = customer.postal_code; }; @@ -34,4 +34,7 @@ Customer.sortBy = function(input, callback){ } }); }; + + + module.exports = Customer \ No newline at end of file diff --git a/models/rental.js b/models/rental.js index e69de29bb..ffc4bbf15 100644 --- a/models/rental.js +++ b/models/rental.js @@ -0,0 +1,26 @@ +var app = require("../app"); +var db = app.get("db"); + +// Constructor function +var Rental = function(rental) { + this.title = rental.title; + this.id = rental.id; + this.checkout_date = rental.checkout_date; + this.due_date = rental.due_date; +}; + +Rental.rentals = function(input,callback){ + // var order = input.shift() + db.run("SELECT * FROM rentals INNER JOIN movies ON rentals.movie_id=movies.id;", function(error, rentals) { + if(error || !rentals) { + callback(error || new Error("Could not retrieve rentals"), undefined); + } else { + callback(null, rentals.map(function(rental) { + return new Rental(rental); + })); + } + }); +} + +module.exports = Rental + From 9738d6f814a24f3372cbb992ae1da7b7e841941d Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 11:09:06 -0700 Subject: [PATCH 048/101] uncommented route --- routes/customers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/customers.js b/routes/customers.js index 5dd16b49d..701c16675 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -4,7 +4,7 @@ var CustomersController = require('../controllers/customers') router.get('/', CustomersController.index) // nothing here, probably omit router.get('/sort/:query', CustomersController.sortBy) -// router.get('/:id/current', CustomersController.current) +router.get('/:id/current', CustomersController.current) // router.get('/:id/history', CustomersController.history) module.exports = router; From bab8874722ca781cd9b0bdd10372f821f3caf1ad Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 12:45:58 -0700 Subject: [PATCH 049/101] comment out history function --- controllers/customers.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index c58f09403..d88d464b7 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -34,7 +34,7 @@ var CustomersController = { current: function(req, res, next) { var id = req.params.id - Rental.rentals(["checked_out", id], function(error, customers) { + Rental.rentals([id,'checked_out'], function(error, customers) { if(error) { var err = new Error("Error retrieving customer list:\n" + error.message); err.status = 500; @@ -45,18 +45,18 @@ var CustomersController = { }); } - history: function(req, res, next) { - var id = req.params.id - Rental.rentals(["returned", id], function(error, customers) { - if(error) { - var err = new Error("Error retrieving customer list:\n" + error.message); - err.status = 500; - next(err); - } else { - res.json(customers) - } - }); - } + // history: function(req, res, next) { + // var id = req.params.id + // Rental.rentals(['returned', id], function(error, customers) { + // if(error) { + // var err = new Error("Error retrieving customer list:\n" + error.message); + // err.status = 500; + // next(err); + // } else { + // res.json(customers) + // } + // }); + // } } module.exports = CustomersController From ceaf128c3914096d27231b03ab570a4dbf98d0a6 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 12:46:47 -0700 Subject: [PATCH 050/101] fixed query for rentals --- models/rental.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/rental.js b/models/rental.js index ffc4bbf15..2a03e8a5f 100644 --- a/models/rental.js +++ b/models/rental.js @@ -11,7 +11,7 @@ var Rental = function(rental) { Rental.rentals = function(input,callback){ // var order = input.shift() - db.run("SELECT * FROM rentals INNER JOIN movies ON rentals.movie_id=movies.id;", function(error, rentals) { + db.run("select * from (select * from rentals,movies where rentals.movie_id=movies.id) as joined where customer_id=$1 and status=$2;",input, function(error, rentals) { if(error || !rentals) { callback(error || new Error("Could not retrieve rentals"), undefined); } else { From 1d65a2a1856dc9fa2b2c6a86aeb73e6bda58ae9a Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 17 Jun 2016 13:00:59 -0700 Subject: [PATCH 051/101] route, action and model query for customers/history path; --- controllers/customers.js | 28 ++++++++++++++-------------- models/rental.js | 17 +++++++++++++++-- routes/customers.js | 2 +- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index d88d464b7..4ffcf46cd 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -34,7 +34,7 @@ var CustomersController = { current: function(req, res, next) { var id = req.params.id - Rental.rentals([id,'checked_out'], function(error, customers) { + Rental.currentCheckedOut([id,'checked_out'], function(error, customers) { if(error) { var err = new Error("Error retrieving customer list:\n" + error.message); err.status = 500; @@ -43,20 +43,20 @@ var CustomersController = { res.json(customers) } }); - } + }, - // history: function(req, res, next) { - // var id = req.params.id - // Rental.rentals(['returned', id], function(error, customers) { - // if(error) { - // var err = new Error("Error retrieving customer list:\n" + error.message); - // err.status = 500; - // next(err); - // } else { - // res.json(customers) - // } - // }); - // } + history: function (req, res, next) { + var id = req.params.id + Rental.all([id], function(error, customers) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers) + } + }); + } } module.exports = CustomersController diff --git a/models/rental.js b/models/rental.js index 2a03e8a5f..f08452410 100644 --- a/models/rental.js +++ b/models/rental.js @@ -7,9 +7,10 @@ var Rental = function(rental) { this.id = rental.id; this.checkout_date = rental.checkout_date; this.due_date = rental.due_date; + this.status = rental.status }; -Rental.rentals = function(input,callback){ +Rental.currentCheckedOut = function(input,callback){ // var order = input.shift() db.run("select * from (select * from rentals,movies where rentals.movie_id=movies.id) as joined where customer_id=$1 and status=$2;",input, function(error, rentals) { if(error || !rentals) { @@ -22,5 +23,17 @@ Rental.rentals = function(input,callback){ }); } -module.exports = Rental +Rental.all = function (input,callback) { + // var order = input.shift() + db.run("select * from (select * from rentals,movies where rentals.movie_id=movies.id) as joined where customer_id=$1 order by due_date;", input, function (error, rentals) { + if(error || !rentals) { + callback(error || new Error("Could not retrieve rentals"), undefined); + } else { + callback(null, rentals.map(function (rental) { + return new Rental(rental); + })); + } + }); +} +module.exports = Rental diff --git a/routes/customers.js b/routes/customers.js index 701c16675..dca9a57db 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -5,6 +5,6 @@ var CustomersController = require('../controllers/customers') router.get('/', CustomersController.index) // nothing here, probably omit router.get('/sort/:query', CustomersController.sortBy) router.get('/:id/current', CustomersController.current) -// router.get('/:id/history', CustomersController.history) +router.get('/:id/history', CustomersController.history) module.exports = router; From 561f4a2137b75fa8adec589ba89a480c5cdafc58 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 17 Jun 2016 13:37:56 -0700 Subject: [PATCH 052/101] route, controller action, and model query for customersWithMovie checked out; --- controllers/movies.js | 17 +++++++++++++---- models/customer.js | 16 +++++++++++++++- routes/movies.js | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index d642f8a90..6d9a12047 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -1,4 +1,5 @@ var Movie = require("../models/movie") +var Customer = require("../models/customer") var MoviesController = { index: function(req, res, next) { @@ -28,11 +29,19 @@ var MoviesController = { } else { res.json(movies) } - })} + })}, - // function current () { - - // }, + current: function (req, res, next) { + var title = req.params.movie + Customer.customersWithMovie([title], function(error, movies) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(movies) + } + })} // function sortedHistory () { diff --git a/models/customer.js b/models/customer.js index fbf2359bf..ff5a4072f 100644 --- a/models/customer.js +++ b/models/customer.js @@ -7,6 +7,8 @@ var Customer = function(customer) { this.name = customer.name; this.registered_at = customer.registered_at; this.postal_code = customer.postal_code; + this.phone = customer.postal_code; + this.account_credit = customer.postal_code; }; @@ -35,6 +37,18 @@ Customer.sortBy = function(input, callback){ }); }; +Customer.customersWithMovie = function(input, callback){ + db.run("SELECT * FROM (SELECT customer_id FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1 and status='checked_out') = movie_id) as new_ids INNER JOIN customers ON (new_ids.customer_id = customers.id);;",input, function(error, customers) { + if(error || !customers) { + callback(error || new Error("Could not retrieve Customers"), undefined); + } else { + callback(null, customers.map(function(customer) { + return new Customer(customer); + })); + } + }); +}; + -module.exports = Customer \ No newline at end of file +module.exports = Customer diff --git a/routes/movies.js b/routes/movies.js index 8596aeffe..612dc8b0f 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -4,7 +4,7 @@ var MoviesController = require('../controllers/movies') router.get('/', MoviesController.index) router.get('/sort/:query', MoviesController.sortBy) -// router.get('/:movie/current', MoviesController.current) +router.get('/:movie/current', MoviesController.current) // router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) From d38a09ee4bd90456b9d186174541b27e967d8eea Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 17 Jun 2016 14:16:32 -0700 Subject: [PATCH 053/101] routes, action, queries for movie title rental history sorted by name or date; --- controllers/movies.js | 15 +++++++++++++-- db/seeds/rentals.json | 7 +++++++ models/customer.js | 23 ++++++++++++++++++++--- routes/movies.js | 2 +- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index 6d9a12047..de70434c5 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -41,11 +41,22 @@ var MoviesController = { } else { res.json(movies) } + })}, + + sortedHistory: function (req, res, next) { + var title = req.params.movie + var sort = req.params.by + Customer.rentedThisMovie([title, sort], function(error, movies) { + if(error) { + var err = new Error("Error retrieving customer list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(movies) + } })} - // function sortedHistory () { - // } } module.exports = MoviesController diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json index a27b71ed8..287d49e73 100644 --- a/db/seeds/rentals.json +++ b/db/seeds/rentals.json @@ -33,5 +33,12 @@ "status": "returned", "checkout_date": "2016-06-02", "due_date": "2016-06-12" +}, +{ +"movie_id": 1, +"customer_id": 4, +"status": "returned", +"checkout_date": "1960-06-03", +"due_date": "1960-06-13" } ] diff --git a/models/customer.js b/models/customer.js index ff5a4072f..de0269600 100644 --- a/models/customer.js +++ b/models/customer.js @@ -7,8 +7,11 @@ var Customer = function(customer) { this.name = customer.name; this.registered_at = customer.registered_at; this.postal_code = customer.postal_code; - this.phone = customer.postal_code; - this.account_credit = customer.postal_code; + this.phone = customer.phone; + this.account_credit = customer.account_credit; + if (customer.checkout_date) { + this.checkout_date = customer.checkout_date + } }; @@ -38,7 +41,21 @@ Customer.sortBy = function(input, callback){ }; Customer.customersWithMovie = function(input, callback){ - db.run("SELECT * FROM (SELECT customer_id FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1 and status='checked_out') = movie_id) as new_ids INNER JOIN customers ON (new_ids.customer_id = customers.id);;",input, function(error, customers) { + db.run("SELECT * FROM (SELECT customer_id FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1 and status='checked_out') = movie_id) as new_ids INNER JOIN customers ON (new_ids.customer_id = customers.id);",input, function(error, customers) { + if(error || !customers) { + callback(error || new Error("Could not retrieve Customers"), undefined); + } else { + callback(null, customers.map(function(customer) { + return new Customer(customer); + })); + } + }); +}; + +Customer.rentedThisMovie = function(input, callback) { + var order = input.pop() + + db.run("SELECT * FROM (SELECT customer_id, checkout_date FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id) as new_ids JOIN customers ON (new_ids.customer_id = customers.id) ORDER BY " + order + ";",input, function(error, customers) { if(error || !customers) { callback(error || new Error("Could not retrieve Customers"), undefined); } else { diff --git a/routes/movies.js b/routes/movies.js index 612dc8b0f..61894b354 100644 --- a/routes/movies.js +++ b/routes/movies.js @@ -5,7 +5,7 @@ var MoviesController = require('../controllers/movies') router.get('/', MoviesController.index) router.get('/sort/:query', MoviesController.sortBy) router.get('/:movie/current', MoviesController.current) -// router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) +router.get('/:movie/history/sort/:by', MoviesController.sortedHistory) module.exports = router; From 2b5c889d0f94a524cb9fd8e4a73967dcfdcaad39 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 15:54:42 -0700 Subject: [PATCH 054/101] uncommented rental routes --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index c1175eb5d..dfe1e69e1 100644 --- a/app.js +++ b/app.js @@ -34,8 +34,8 @@ app.use('/movies', moviesRoutes); var customersRoutes = require('./routes/customers'); app.use('/customers', customersRoutes); -// var rentalsRoutes = require('./routes/rentals'); -// app.use('/rentals', rentalsRoutes); +var rentalsRoutes = require('./routes/rentals'); +app.use('/rentals', rentalsRoutes); // catch 404 and forward to error handler app.use(function(req, res, next) { From 9d65f387f178e296637134809fe7fcefdfe688eb Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 15:54:55 -0700 Subject: [PATCH 055/101] uncommented rental routes --- routes/rentals.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/rentals.js b/routes/rentals.js index 422905c03..3d5fc62a3 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -3,9 +3,9 @@ var router = express.Router(); var RentalsController = require('../controllers/rentals') router.get('/:movie', RentalsController.lookupMovie) -router.get('/:movie/customers', RentalsController.sortBy) // do we need to pass stuff in? -router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title -router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title -router.get('/overdue', RentalsController.overdue) +// router.get('/:movie/customers', RentalsController.sortBy) // do we need to pass stuff in? +// router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title +// router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title +// router.get('/overdue', RentalsController.overdue) module.exports = router; From 2c361ced8519b12d37034608e7c5c535494d1287 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 15:55:16 -0700 Subject: [PATCH 056/101] added movie lookup method --- controllers/rentals.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 79d19aca1..83ca9075b 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -1,24 +1,36 @@ +var Rental = require("../models/rental") +var Movie = require("../models/movie") + var RentalsController = { - function lookupMovie () { + lookupMovie: function (req, res, next) { + var title = req.params.movie - }, + Movie.rentalInfo([title], function(error, rentals) { + if(error) { + var err = new Error("Error retrieving movie info:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(rentals) + } + })} - function sortBy () { + // function sortBy () { - }, + // }, - function checkOut () { + // function checkOut () { - }, + // }, - function return () { + // function return () { - }, + // }, - function overdue () { + // function overdue () { - } + // } } -modules.exports = RentalsController +module.exports = RentalsController From 331ead80154895c5bb6bfa664799eb23af00a616 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 17 Jun 2016 15:55:48 -0700 Subject: [PATCH 057/101] added method for rental info --- models/movie.js | 17 +++++++++++++++++ models/rental.js | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/models/movie.js b/models/movie.js index 698d2be67..6a3d70e50 100644 --- a/models/movie.js +++ b/models/movie.js @@ -6,6 +6,11 @@ var Movie = function(movie) { this.id = movie.id; this.title = movie.title; this.release = movie.release_date; + this.overview = movie.overview; + this.inventory = movie.inventory; + if (movie.available_inventory) { + this.available_inventory = movie.available_inventory + } }; @@ -34,4 +39,16 @@ Movie.sortBy = function(input, callback){ }); }; +Movie.rentalInfo = function(input, callback) { + db.run("SELECT overview, release_date, inventory, (inventory - (SELECT count(*)FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id AND status='checked_out')) as available_inventory FROM movies WHERE title = $1;",input, function(error, movie) { + if(error || !movie) { + callback(error || new Error("Could not retrieve movie info"), undefined); + } else { + callback(null, movie.map(function(movie) { + return new Movie(movie); + })); + } + }); +}; + module.exports = Movie \ No newline at end of file diff --git a/models/rental.js b/models/rental.js index f08452410..00c0f54db 100644 --- a/models/rental.js +++ b/models/rental.js @@ -25,7 +25,7 @@ Rental.currentCheckedOut = function(input,callback){ Rental.all = function (input,callback) { // var order = input.shift() - db.run("select * from (select * from rentals,movies where rentals.movie_id=movies.id) as joined where customer_id=$1 order by due_date;", input, function (error, rentals) { + db.run("SELECT * FROM (SELECT customer_id, checkout_date FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id) as new_ids JOIN customers ON (new_ids.customer_id = customers.id) ORDER BY " + order + ";", input, function (error, rentals) { if(error || !rentals) { callback(error || new Error("Could not retrieve rentals"), undefined); } else { @@ -36,4 +36,5 @@ Rental.all = function (input,callback) { }); } + module.exports = Rental From 81a42a902679e7b892840611fda51d52ca20fe19 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 10:49:35 -0700 Subject: [PATCH 058/101] Update script to use istanbul for test coverage; --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index a25be8949..55ab720b2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "start": "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:drop": "dropdb cassettecollection", "db:create": "createdb cassettecollection", "db:schema": "node tasks/load_schema.js", @@ -23,6 +23,7 @@ "serve-favicon": "~2.3.0" }, "devDependencies": { + "istanbul": "^0.4.4", "jasmine-node": "^1.14.5", "nodemon": "^1.9.2", "request": "^2.72.0" From b5b83b7d7fd5a59a290e7b29c6c0db46afa4361a Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 10:50:09 -0700 Subject: [PATCH 059/101] Setup a view file for the docs and include new routes; --- public/stylesheets/style.css | 31 +++++++++++++++++++++++++++++-- routes/index.js | 8 ++++++++ views/docs.jade | 10 ++++++++++ views/layout.jade | 1 + 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 views/docs.jade diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 9453385b9..e2e034f88 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -1,8 +1,35 @@ body { - padding: 50px; - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; + padding: 0 50px 50px 50px; + background-color: #f8f9f8; + font-size: : 16px; + font-family: 'Open Sans', sans-serif; +} + +h1, h2 { + font-family: 'Gloria Hallelujah', cursive; +} + +h1 { + font-size: 4rem; } a { color: #00B7FF; + text-decoration: none; +} + +.docs-container { + width: 70%; + margin: auto; + text-align: center; +} + +.docs-container h1 { + margin: 0; +} + +.docs-container img { + display: block; + width: 60%; + margin: auto; } diff --git a/routes/index.js b/routes/index.js index 21b4f7e34..3f94b731a 100644 --- a/routes/index.js +++ b/routes/index.js @@ -10,6 +10,14 @@ router.get('/zomg', function(req, res, next) { res.status(200).json({message: 'it works!'}) }); +router.get('/api/docs', function(req, res, next) { + res.render('docs') +}); + +router.get('/api/docs.json', function(req, res, next) { + res.status(200).json({message: 'docs, yo!'}) +}); + module.exports = router; diff --git a/views/docs.jade b/views/docs.jade new file mode 100644 index 000000000..999ed61c2 --- /dev/null +++ b/views/docs.jade @@ -0,0 +1,10 @@ +doctype html +html + head + title= title + link(rel='stylesheet', href='/stylesheets/style.css') + link(rel='stylesheet', href='https://fonts.googleapis.com/css?family=Gloria+Hallelujah|Open+Sans:300') + body + .docs-container + h1 Cassette Collection + img(src='http://londoninspiration.com/wp-content/uploads/2014/01/vhs.jpg') diff --git a/views/layout.jade b/views/layout.jade index 15af079bf..af974804d 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -3,5 +3,6 @@ html head title= title link(rel='stylesheet', href='/stylesheets/style.css') + link(rel='stylesheet', href='https://fonts.googleapis.com/css?family=Gloria+Hallelujah|Open+Sans:300') body block content From 3e39da0951b4bf8d7cf712bf85e847acf55218f4 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 11:17:30 -0700 Subject: [PATCH 060/101] Created json file for docs; --- docs.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs.json diff --git a/docs.json b/docs.json new file mode 100644 index 000000000..0793bbd40 --- /dev/null +++ b/docs.json @@ -0,0 +1,15 @@ +p The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. + +p The API endpoint is available at https://cassettecollection.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL. + +h2 API Specification + +p This is version 1 of the Cassette Collection. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/. + +h3 Search for suggestions + +Search for food and music suggestions given a particular search term, and an optional limit for number of results. + +h4 Request + +Search requests are GET requests to the /v1/suggestions/search endpoint with the following parameters: From 241ee8baf4056d95f39c4158b4072c9db6d9fe45 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 11:18:01 -0700 Subject: [PATCH 061/101] Added some placeholder text for docs view and styled; --- public/stylesheets/style.css | 9 ++++---- views/docs.jade | 45 ++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index e2e034f88..b408a4841 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -5,7 +5,7 @@ body { font-family: 'Open Sans', sans-serif; } -h1, h2 { +h1, h2, h3, h4 { font-family: 'Gloria Hallelujah', cursive; } @@ -21,14 +21,15 @@ a { .docs-container { width: 70%; margin: auto; - text-align: center; + /*text-align: center;*/ } -.docs-container h1 { +.docs-header h1 { margin: 0; + text-align: center; } -.docs-container img { +.docs-header img { display: block; width: 60%; margin: auto; diff --git a/views/docs.jade b/views/docs.jade index 999ed61c2..0b4d8ae9e 100644 --- a/views/docs.jade +++ b/views/docs.jade @@ -6,5 +6,46 @@ html link(rel='stylesheet', href='https://fonts.googleapis.com/css?family=Gloria+Hallelujah|Open+Sans:300') body .docs-container - h1 Cassette Collection - img(src='http://londoninspiration.com/wp-content/uploads/2014/01/vhs.jpg') + .docs-header + h1 Cassette Collection + img(src='http://londoninspiration.com/wp-content/uploads/2014/01/vhs.jpg') + .docs-info + p The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. + + p The API endpoint is available at https://cassettecollection.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL. + + h2 API Specification + + p This is version 1 of the Cassette Collection. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/. + + h2 Search for suggestions + + p Search for food and music suggestions given a particular search term, and an optional limit for number of results. + + h3 Request + + p Search requests are GET requests to the /v1/suggestions/search endpoint with the following parameters: + + p blah + + h3 Response + + p Search results are JSON documents containing a list of suggestion hashes, and a canonical URL for the request itself. Each suggestion hash includes the ID for a specific business from the Yelp API as well as an ID and type for an item from the Spotify API. + + p Both IDs are string values, and the type for the music item is one of artist, album, track. + + p Wherever possible, the Tunes & Takeout API is written to provide consistent results for the same queries. This can aid with caching, but it cannot be guaranteed. Because the Tunes & Takeout API relies upon the Yelp and Spotify APIs, when their data changes the results of particular search queries may also change. + + p If the request was not successful, the following HTTP status codes may be returned depending on the specific error: + + p 400 - The request parameters were invalid. Either the query was missing, or the limit was not an integer between 1 and 100. + + h2 Examples + + h3 Simple query without a limit + + p Request URL: + + p GET: + + code /v1/suggestions/search?query=banana From 49f365b5da566e6b6ed8ed3cc10c8eb7268733a8 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 12:55:31 -0700 Subject: [PATCH 062/101] Rentals overdue action, route, and query; --- controllers/rentals.js | 19 +++++++++++++++---- models/rental.js | 16 +++++++++++++++- routes/rentals.js | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 83ca9075b..65036910f 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -6,7 +6,7 @@ var RentalsController = { lookupMovie: function (req, res, next) { var title = req.params.movie - Movie.rentalInfo([title], function(error, rentals) { + Movie.rentalInfo([title], function (error, rentals) { if(error) { var err = new Error("Error retrieving movie info:\n" + error.message); err.status = 500; @@ -14,7 +14,7 @@ var RentalsController = { } else { res.json(rentals) } - })} + })}, // function sortBy () { @@ -28,9 +28,20 @@ var RentalsController = { // }, - // function overdue () { + overdue: function (req, res, next) { - // } + console.log("ohs ") + + Rental.overdueList(function (error, rentals) { + if(error) { + var err = new Error("Error retrieving overdue list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(rentals) + } + }); + } } module.exports = RentalsController diff --git a/models/rental.js b/models/rental.js index 00c0f54db..362f430f4 100644 --- a/models/rental.js +++ b/models/rental.js @@ -8,6 +8,7 @@ var Rental = function(rental) { this.checkout_date = rental.checkout_date; this.due_date = rental.due_date; this.status = rental.status + this.name = rental.name }; Rental.currentCheckedOut = function(input,callback){ @@ -23,7 +24,7 @@ Rental.currentCheckedOut = function(input,callback){ }); } -Rental.all = function (input,callback) { +Rental.all = function (input, callback) { // var order = input.shift() db.run("SELECT * FROM (SELECT customer_id, checkout_date FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id) as new_ids JOIN customers ON (new_ids.customer_id = customers.id) ORDER BY " + order + ";", input, function (error, rentals) { if(error || !rentals) { @@ -36,5 +37,18 @@ Rental.all = function (input,callback) { }); } +Rental.overdueList = function (callback) { + // var order = input.shift() + db.run("SELECT customers.name, movies.title, checkout_date, due_date FROM (SELECT customer_id, movie_id, due_date, checkout_date FROM rentals WHERE status='overdue') as overdues INNER JOIN customers ON (overdues.customer_id = customers.id) INNER JOIN movies ON (overdues.movie_id = movies.id);", function (error, rentals) { + console.log("halp") + if(error || !rentals) { + callback(error || new Error("Could not retrieve rentals"), undefined); + } else { + callback(null, rentals.map(function (rental) { + return new Rental(rental); + })); + } + }); +} module.exports = Rental diff --git a/routes/rentals.js b/routes/rentals.js index 3d5fc62a3..6a73b8f29 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -2,10 +2,10 @@ var express = require('express'); var router = express.Router(); var RentalsController = require('../controllers/rentals') +router.get('/overdue', RentalsController.overdue) router.get('/:movie', RentalsController.lookupMovie) // router.get('/:movie/customers', RentalsController.sortBy) // do we need to pass stuff in? // router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title // router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title -// router.get('/overdue', RentalsController.overdue) module.exports = router; From fb89d7236bdcf8a413327c9add0f56e41ffd3cbe Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Mon, 20 Jun 2016 13:48:16 -0700 Subject: [PATCH 063/101] added function for currently checked out movies --- controllers/rentals.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 65036910f..39f33cbf4 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -1,5 +1,6 @@ var Rental = require("../models/rental") var Movie = require("../models/movie") +var Customer = require("../models/customer") var RentalsController = { @@ -16,9 +17,19 @@ var RentalsController = { } })}, - // function sortBy () { + currentlyCheckedOut: function (req, res, next) { + var title = req.params.movie - // }, + Customer.currentlyCheckedOut([title],function (error, customers) { + if(error) { + var err = new Error("Error retrieving overdue list:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(customers) + } + }); + }, // function checkOut () { From da6a0f292ecf10a2180e15451a477a5afdd5a5c1 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Mon, 20 Jun 2016 13:48:34 -0700 Subject: [PATCH 064/101] uncommented and change function name for rental route --- routes/rentals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/rentals.js b/routes/rentals.js index 6a73b8f29..8bb38f497 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -3,8 +3,8 @@ var router = express.Router(); var RentalsController = require('../controllers/rentals') router.get('/overdue', RentalsController.overdue) +router.get('/:movie/customers', RentalsController.currentlyCheckedOut) // do we need to pass stuff in? router.get('/:movie', RentalsController.lookupMovie) -// router.get('/:movie/customers', RentalsController.sortBy) // do we need to pass stuff in? // router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title // router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title From 02608dd97ad2856b925b59345ef4d99696f13db1 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Mon, 20 Jun 2016 13:48:52 -0700 Subject: [PATCH 065/101] added currentlycheckedout function --- models/customer.js | 16 ++++++++++++++++ models/rental.js | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/models/customer.js b/models/customer.js index de0269600..34505c185 100644 --- a/models/customer.js +++ b/models/customer.js @@ -12,6 +12,9 @@ var Customer = function(customer) { if (customer.checkout_date) { this.checkout_date = customer.checkout_date } + if (customer.due_date) { + this.due_date = customer.due_date + } }; @@ -66,6 +69,19 @@ Customer.rentedThisMovie = function(input, callback) { }); }; +Customer.currentlyCheckedOut = function (input,callback) { + // var order = input.shift() + db.run("SELECT customers.name, checkout_date, due_date, movies.title FROM (SELECT customer_id, due_date, checkout_date, movie_id FROM rentals WHERE status='checked_out' OR status='overdue') as checkout INNER JOIN customers ON (checkout.customer_id = customers.id) INNER JOIN movies ON (checkout.movie_id = movies.id) WHERE movies.title=$1;",input, function (error, customers) { + console.log("halp") + if(error || !customers) { + callback(error || new Error("Could not retrieve rentals"), undefined); + } else { + callback(null, customers.map(function (customer) { + return new Customer(customer); + })); + } + }); +} module.exports = Customer diff --git a/models/rental.js b/models/rental.js index 362f430f4..e43f173bc 100644 --- a/models/rental.js +++ b/models/rental.js @@ -24,9 +24,9 @@ Rental.currentCheckedOut = function(input,callback){ }); } -Rental.all = function (input, callback) { +Rental.all = function (input,callback) { // var order = input.shift() - db.run("SELECT * FROM (SELECT customer_id, checkout_date FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id) as new_ids JOIN customers ON (new_ids.customer_id = customers.id) ORDER BY " + order + ";", input, function (error, rentals) { + db.run("select * from (select * from rentals,movies where rentals.movie_id=movies.id) as joined where customer_id=$1 order by due_date;", input, function (error, rentals) { if(error || !rentals) { callback(error || new Error("Could not retrieve rentals"), undefined); } else { @@ -51,4 +51,17 @@ Rental.overdueList = function (callback) { }); } + +// Rental.all = function (input, callback) { +// var order = input.shift() +// db.run("SELECT * FROM (SELECT customer_id, checkout_date FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id) as new_ids JOIN customers ON (new_ids.customer_id = customers.id) ORDER BY " + order + ";", input, function (error, rentals) { +// if(error || !rentals) { +// callback(error || new Error("Could not retrieve rentals"), undefined); +// } else { +// callback(null, rentals.map(function (rental) { +// return new Rental(rental); +// })); +// } +// }); +// } module.exports = Rental From 7e2814e308b20b661d38d5fb824540690105eabb Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 16:19:46 -0700 Subject: [PATCH 066/101] Checkout adds a record into rentals table with correct ids and dates; --- controllers/rentals.js | 17 +++++++++--- models/rental.js | 61 +++++++++++++++++++++++++++++++++++++++++- routes/rentals.js | 4 +-- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 39f33cbf4..457fbe8ba 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -31,9 +31,20 @@ var RentalsController = { }); }, - // function checkOut () { - - // }, + checkOut: function (req, res, next) { + var title = req.params.movie + var id = 55 + console.log("HALP") + Rental.checkOut([title, id],function (error, rental) { + if(error) { + var err = new Error("Error checking out rental:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json([{"sample": "BLAH"}]) + } + }); + }, // function return () { diff --git a/models/rental.js b/models/rental.js index e43f173bc..7e4553db5 100644 --- a/models/rental.js +++ b/models/rental.js @@ -38,7 +38,6 @@ Rental.all = function (input,callback) { } Rental.overdueList = function (callback) { - // var order = input.shift() db.run("SELECT customers.name, movies.title, checkout_date, due_date FROM (SELECT customer_id, movie_id, due_date, checkout_date FROM rentals WHERE status='overdue') as overdues INNER JOIN customers ON (overdues.customer_id = customers.id) INNER JOIN movies ON (overdues.movie_id = movies.id);", function (error, rentals) { console.log("halp") if(error || !rentals) { @@ -51,6 +50,66 @@ Rental.overdueList = function (callback) { }); } +Rental.checkOut = function (input, callback) { + db.run("SELECT id FROM movies WHERE title=$1;", input, function (error, found_id) { + console.log("id? ",found_id) + db.rentals.save({customer_id: input[1], movie_id: found_id, due_date: due(), checkout_date: today(), status: "checked_out"}, function (error, rentals) { + rentals = [rentals] + if(error || !rentals) { + callback(error || new Error("Could not retrieve rentals"), undefined); + } else { + db.run("UPDATE movies SET inventory=inventory-1 WHERE title=$1;", input, function (error, meh) {}) + callback(null, rentals.map(function (rental) { + return new Rental(rental); + })) + } + }) + }) +} + +due = function () { + date = new Date(Date.now() + 1000000000) // uhh magic number.. adds 12 days + + yr = date.getFullYear().toString() + mo = (date.getMonth()+1).toString() + mo = mo[1] ? mo : "0" + mo[0] + da = date.getDate().toString() + da = da[1] ? da : "0" + da[0] + fdate = yr + "-" + mo + "-" + da + console.log(fdate) + return fdate + +} + +today = function () { + date = new Date(Date.now()) + + yr = date.getFullYear().toString() + mo = (date.getMonth()+1).toString() + mo = mo[1] ? mo : "0" + mo[0] + da = date.getDate().toString() + da = da[1] ? da : "0" + da[0] + fdate = yr + "-" + mo + "-" + da + console.log(fdate) + return fdate +} + +// Rental.overdueList = function (input, callback) { +// db.run("SELECT id FROM movies WHERE title=$1;", input, db.rentals.save(error , function (error, rentals) { +// console.log("halp") +// if(error || !rentals) { +// callback(error || new Error("Could not retrieve rentals"), undefined); +// } else { +// callback(null, rentals.map(function (rental) { +// return new Rental(rental); +// })); +// } +// })) +// } + + + + // Rental.all = function (input, callback) { // var order = input.shift() diff --git a/routes/rentals.js b/routes/rentals.js index 8bb38f497..1a944caa1 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -3,9 +3,9 @@ var router = express.Router(); var RentalsController = require('../controllers/rentals') router.get('/overdue', RentalsController.overdue) +router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title router.get('/:movie/customers', RentalsController.currentlyCheckedOut) // do we need to pass stuff in? -router.get('/:movie', RentalsController.lookupMovie) -// router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title // router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title +router.get('/:movie', RentalsController.lookupMovie) module.exports = router; From 23bf75aea543188238f1deeda6f76880173b6b3d Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 16:30:30 -0700 Subject: [PATCH 067/101] Checkout subtracts one from the movie's inventory; --- models/rental.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/models/rental.js b/models/rental.js index 7e4553db5..02b56b870 100644 --- a/models/rental.js +++ b/models/rental.js @@ -51,14 +51,14 @@ Rental.overdueList = function (callback) { } Rental.checkOut = function (input, callback) { - db.run("SELECT id FROM movies WHERE title=$1;", input, function (error, found_id) { - console.log("id? ",found_id) - db.rentals.save({customer_id: input[1], movie_id: found_id, due_date: due(), checkout_date: today(), status: "checked_out"}, function (error, rentals) { + db.movies.findOne({title: input[0]}, function (error, found_id) { + console.log(found_id.id) + db.run("UPDATE movies SET inventory=inventory-1 WHERE title=$1;", [found_id.title], function (error, meh) {}) + db.rentals.save({customer_id: input[1], movie_id: found_id.id, due_date: due(), checkout_date: today(), status: "checked_out"}, function (error, rentals) { rentals = [rentals] if(error || !rentals) { callback(error || new Error("Could not retrieve rentals"), undefined); } else { - db.run("UPDATE movies SET inventory=inventory-1 WHERE title=$1;", input, function (error, meh) {}) callback(null, rentals.map(function (rental) { return new Rental(rental); })) @@ -76,7 +76,6 @@ due = function () { da = date.getDate().toString() da = da[1] ? da : "0" + da[0] fdate = yr + "-" + mo + "-" + da - console.log(fdate) return fdate } @@ -90,7 +89,6 @@ today = function () { da = date.getDate().toString() da = da[1] ? da : "0" + da[0] fdate = yr + "-" + mo + "-" + da - console.log(fdate) return fdate } From 5a19a01f516580bd1b08742e6885069197c43522 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 16:52:44 -0700 Subject: [PATCH 068/101] Checkout returns the new record's info; --- controllers/rentals.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 457fbe8ba..0535a6e71 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -34,14 +34,15 @@ var RentalsController = { checkOut: function (req, res, next) { var title = req.params.movie var id = 55 - console.log("HALP") + console.log(req.body) + Rental.checkOut([title, id],function (error, rental) { if(error) { var err = new Error("Error checking out rental:\n" + error.message); err.status = 500; next(err); } else { - res.json([{"sample": "BLAH"}]) + res.json(rental) } }); }, From beebdf21c9f7dfcb24b9741ac729fb6c71f45203 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 17:14:36 -0700 Subject: [PATCH 069/101] Created rental return route, query, and action; --- controllers/rentals.js | 18 +++++++++++++++--- models/rental.js | 20 +++++++++++++++++++- routes/rentals.js | 2 +- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/controllers/rentals.js b/controllers/rentals.js index 0535a6e71..62ad4c177 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -34,7 +34,7 @@ var RentalsController = { checkOut: function (req, res, next) { var title = req.params.movie var id = 55 - console.log(req.body) + console.log(req.body.customer_id) // need to test to see if customer's id comes in body Rental.checkOut([title, id],function (error, rental) { if(error) { @@ -47,9 +47,21 @@ var RentalsController = { }); }, - // function return () { + return: function (req, res, next) { + var title = req.params.movie + var id = 55 + console.log(req.body.customer_id) // need to test to see if customer's id comes in body - // }, + Rental.return([title, id],function (error, rental) { + if(error) { + var err = new Error("Error checking out rental:\n" + error.message); + err.status = 500; + next(err); + } else { + res.json(rental) + } + }); + }, overdue: function (req, res, next) { diff --git a/models/rental.js b/models/rental.js index 02b56b870..3e551a91b 100644 --- a/models/rental.js +++ b/models/rental.js @@ -52,7 +52,6 @@ Rental.overdueList = function (callback) { Rental.checkOut = function (input, callback) { db.movies.findOne({title: input[0]}, function (error, found_id) { - console.log(found_id.id) db.run("UPDATE movies SET inventory=inventory-1 WHERE title=$1;", [found_id.title], function (error, meh) {}) db.rentals.save({customer_id: input[1], movie_id: found_id.id, due_date: due(), checkout_date: today(), status: "checked_out"}, function (error, rentals) { rentals = [rentals] @@ -67,6 +66,25 @@ Rental.checkOut = function (input, callback) { }) } +Rental.return = function (input, callback) { + db.movies.findOne({title: input[0]}, function (error, found_id) { + db.run("UPDATE movies SET inventory=inventory+1 WHERE title=$1;", [found_id.title], function (error, meh) {}) + + db.rentals.findOne({movie_id: found_id.id, customer_id: input[1], status: "checked_out"}, function (error, rental) { + db.rentals.update({id: rental.id, status: "returned"}, function (error, rentals) { + rentals = [rentals] + if(error || !rentals) { + callback(error || new Error("Could not retrieve rentals"), undefined); + } else { + callback(null, rentals.map(function (rental) { + return new Rental(rental); + })) + } + }) + }) + }) +} + due = function () { date = new Date(Date.now() + 1000000000) // uhh magic number.. adds 12 days diff --git a/routes/rentals.js b/routes/rentals.js index 1a944caa1..19cc793db 100644 --- a/routes/rentals.js +++ b/routes/rentals.js @@ -5,7 +5,7 @@ var RentalsController = require('../controllers/rentals') router.get('/overdue', RentalsController.overdue) router.post('/:movie/check-out', RentalsController.checkOut) // requires json data customer_id and movie title router.get('/:movie/customers', RentalsController.currentlyCheckedOut) // do we need to pass stuff in? -// router.post('/:movie/return', RentalsController.return) // requires json data customer_id and movie title +router.put('/:movie/return', RentalsController.return) // requires json data customer_id and movie title router.get('/:movie', RentalsController.lookupMovie) module.exports = router; From 752e9381d35577393f5ae1f1c4710e5de92a52c9 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 20 Jun 2016 17:16:43 -0700 Subject: [PATCH 070/101] Added a note about how we're getting the data for id; --- controllers/rentals.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/controllers/rentals.js b/controllers/rentals.js index 62ad4c177..22b8e6125 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -35,6 +35,8 @@ var RentalsController = { var title = req.params.movie var id = 55 console.log(req.body.customer_id) // need to test to see if customer's id comes in body + // if we don't want to have them passed in the body we can alter the url to take a + // second parameter ->/rentals/:movie/check-out/:cust_id Rental.checkOut([title, id],function (error, rental) { if(error) { From 623f9742580a087f1adfc05fbfa5cf7a0ab87b6c Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 21 Jun 2016 16:04:55 -0700 Subject: [PATCH 071/101] started the docs.json file; --- docs.json | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs.json b/docs.json index 0793bbd40..5dd5f4619 100644 --- a/docs.json +++ b/docs.json @@ -1,4 +1,4 @@ -p The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. +/*p The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. p The API endpoint is available at https://cassettecollection.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL. @@ -12,4 +12,19 @@ Search for food and music suggestions given a particular search term, and an opt h4 Request -Search requests are GET requests to the /v1/suggestions/search endpoint with the following parameters: +Search requests are GET requests to the /v1/suggestions/search endpoint with the following parameters:*/ + +[ + "CassetteCollection": "The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. The API endpoint is available at https://tunes-takeout-api.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL.", + "API_Specification": + "Request": "This is version 1 of the Tunes & Takeout API. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/.", + "Response": "Search results are JSON documents containing a list of suggestion hashes, and a canonical URL for the request itself. Each suggestion hash includes the ID for a specific business from the Yelp API as well as an ID and type for an item from the Spotify API. + + Both IDs are string values, and the type for the music item is one of artist, album, track. + + Wherever possible, the Tunes & Takeout API is written to provide consistent results for the same queries. This can aid with caching, but it cannot be guaranteed. Because the Tunes & Takeout API relies upon the Yelp and Spotify APIs, when their data changes the results of particular search queries may also change. + + If the request was not successful, the following HTTP status codes may be returned depending on the specific error: + + 400 - The request parameters were invalid. Either the query was missing, or the limit was not an integer between 1 and 100." +] From 58689464a668c0d08e82a9ae723c9c33fb0c742f Mon Sep 17 00:00:00 2001 From: sophia Date: Tue, 21 Jun 2016 16:05:27 -0700 Subject: [PATCH 072/101] Set up seperate dev and test environments with seperate databased; --- app.js | 3 +-- package.json | 7 ++++--- tasks/load_schema.js | 25 ++++++++++++++++++++++--- tasks/seed_data.js | 23 ++++++++++++++++++++++- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index dfe1e69e1..65de7aa27 100644 --- a/app.js +++ b/app.js @@ -9,7 +9,7 @@ var massive = require('massive') var app = express(); module.exports = app; -var connectionString = "postgres://localhost/cassettecollection" +var connectionString = "postgres://localhost/cassettecollection_" + app.get('env') var db = massive.connectSync({connectionString : connectionString}) app.set("db", db) // view engine setup @@ -68,5 +68,4 @@ app.use(function(err, req, res, next) { }); }); - module.exports = app; diff --git a/package.json b/package.json index 55ab720b2..bb500c59c 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,11 @@ "version": "0.0.0", "private": true, "scripts": { - "start": "nodemon ./bin/www", + "start": "./node_modules/.bin/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/", - "db:drop": "dropdb cassettecollection", - "db:create": "createdb cassettecollection", + "db:drop": "dropdb cassettecollection_development && dropdb cassettecollection_test", + "db:create": "createdb cassettecollection_development; createdb cassettecollection_test", "db:schema": "node tasks/load_schema.js", "db:seed": "node tasks/seed_data.js", "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" diff --git a/tasks/load_schema.js b/tasks/load_schema.js index 7e9466d4e..6755c455a 100644 --- a/tasks/load_schema.js +++ b/tasks/load_schema.js @@ -1,13 +1,32 @@ var massive = require('massive') -var connectionString = "postgres://localhost/cassettecollection" +var connectionString = "postgres://localhost/cassettecollection_development" +var connectionString_test = "postgres://localhost/cassettecollection_test" var db = massive.connectSync({connectionString : connectionString}) +var db_test = massive.connectSync({connectionString : connectionString_test}) + +var count = 0 db.setup.schema([], function(err, res) { if (err) { throw(new Error(err.message)) } - console.log("yay schema!") - process.exit() + count += 1 + console.log("yay schema1!") + checkFinish() +}) + +db_test.setup.schema([], function(err, res) { + if (err) { + throw(new Error(err.message)) + } + + count += 1 + console.log("yay schema2!") + checkFinish() }) + +function checkFinish() { + if (count >= 2) { process.exit() } +} diff --git a/tasks/seed_data.js b/tasks/seed_data.js index bf5480745..875aaaf28 100644 --- a/tasks/seed_data.js +++ b/tasks/seed_data.js @@ -1,7 +1,10 @@ var massive = require('massive') -var connectionString = "postgres://localhost/cassettecollection" +var connectionString = "postgres://localhost/cassettecollection_development" +var connectionString_test = "postgres://localhost/cassettecollection_test" var db = massive.connectSync({connectionString : connectionString}) +var db_test = massive.connectSync({connectionString : connectionString_test}) + var movies_data = require("../db/seeds/movies") var customers_data = require("../db/seeds/customers") var rentals_data = require("../db/seeds/rentals") @@ -17,6 +20,12 @@ function seed() { if (err) { throw new Error(err.message) } + }) + + db_test.movies.save(movie, function (err,res) { + if (err) { + throw new Error(err.message) + } moviesCount++ checkFinish() }) @@ -27,6 +36,12 @@ function seed() { if (err) { throw new Error(err.message) } + }) + + db_test.customers.save(customer, function (err,res) { + if (err) { + throw new Error(err.message) + } customersCount++ checkFinish() }) @@ -37,6 +52,12 @@ function seed() { if (err) { throw new Error(err.message) } + }) + + db_test.rentals.save(rental, function (err,res) { + if (err) { + throw new Error(err.message) + } rentalsCount++ checkFinish() }) From d654c628f77d50336239e96a8ebb1b93fdc8f6ce Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 22 Jun 2016 13:01:54 -0700 Subject: [PATCH 073/101] Change test script so it doesn't instrument test files; --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb500c59c..e282a4831 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "./node_modules/.bin/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:drop": "dropdb cassettecollection_development && dropdb cassettecollection_test", "db:create": "createdb cassettecollection_development; createdb cassettecollection_test", "db:schema": "node tasks/load_schema.js", From 58b2bace0eb88cf98dbdc5f74333f7ab4f3d9094 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 22 Jun 2016 13:46:12 -0700 Subject: [PATCH 074/101] Create model test files; --- spec/models/customer.spec.js | 17 +++++++++++++++++ spec/models/movie.spec.js | 21 +++++++++++++++++++++ spec/models/rental.spec.js | 17 +++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 spec/models/customer.spec.js create mode 100644 spec/models/movie.spec.js create mode 100644 spec/models/rental.spec.js diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js new file mode 100644 index 000000000..44edc4388 --- /dev/null +++ b/spec/models/customer.spec.js @@ -0,0 +1,17 @@ +var app = require('../../app') +var db = app.get('db') + +var Movie = require('../../models/customer') + +describe('Customer', function () { + + afterEach(function () { + db.end() + }) + + describe('', function () { + + + }) + +} diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js new file mode 100644 index 000000000..ae4773df1 --- /dev/null +++ b/spec/models/movie.spec.js @@ -0,0 +1,21 @@ +var app = require('../../app') +var db = app.get('db') + +var Movie = require('../../models/movie') + +describe('Movie', function () { + var title = 'High Noon' + var overview = 'High Noon is about a recently freed leader of a gang of bandits in the desert who is looking to get revenge on the Sheriff who put him in jail. A legendary western film from the Austrian director Fred Zinnemann.' + var release_date = '1952-07-24' + var inventory = 4 + + afterEach(function () { + db.end() + }) + + describe('all', function () { + + + }) + +} diff --git a/spec/models/rental.spec.js b/spec/models/rental.spec.js new file mode 100644 index 000000000..a18487ee2 --- /dev/null +++ b/spec/models/rental.spec.js @@ -0,0 +1,17 @@ +var app = require('../../app') +var db = app.get('db') + +var Movie = require('../../models/rental') + +describe('Rental', function () { + + afterEach(function () { + db.end() + }) + + describe('', function () { + + + }) + +} From 74e2d4a8bc39c4dac855f424305643da059ddfb8 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Wed, 22 Jun 2016 14:27:13 -0700 Subject: [PATCH 075/101] model ovie testing. NOT WORKING --- .gitignore | 1 + npm-debug.log | 49 +++++++++++++++++++++++++++++++++ package.json | 2 +- spec/controllers/movies.spec.js | 8 +++++- spec/models/customer.spec.js | 11 ++++++-- spec/models/movie.spec.js | 15 ++++++++-- spec/models/rental.spec.js | 2 +- 7 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 npm-debug.log diff --git a/.gitignore b/.gitignore index 646ac519e..2f9bd06a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store node_modules/ +coverage/ \ No newline at end of file diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 000000000..90ab790c4 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,49 @@ +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 'test' ] +2 info using npm@3.9.3 +3 info using node@v6.2.1 +4 verbose run-script [ 'pretest', 'test', 'posttest' ] +5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 +6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing +7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 +8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true +9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Nadine/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/Nadine/.rvm/gems/ruby-2.3.0/bin:/Users/Nadine/.rvm/gems/ruby-2.3.0@global/bin:/Users/Nadine/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Nadine/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/Nadine/C5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', +11 silly lifecycle 'clear; ./node_modules/.bin/istanbul cover -x \'spec/**/*\' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] +12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null +13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script +14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` +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/Nadine/C5/projects/VideoStoreAPI +17 error Darwin 15.0.0 +18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" +19 error node v6.2.1 +20 error npm v3.9.3 +21 error code ELIFECYCLE +22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. +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_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ +23 error You can get information on how to open an issue for this project with: +23 error npm bugs video-store-api +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls video-store-api +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index e282a4831..57c3c81fc 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "start": "./node_modules/.bin/nodemon ./bin/www", "start-test": "NODE_ENV=test ./node_modules/.bin/nodemon ./bin/www", - "test": "clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --verbose spec/", + "test": "clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/", "db:drop": "dropdb cassettecollection_development && dropdb cassettecollection_test", "db:create": "createdb cassettecollection_development; createdb cassettecollection_test", "db:schema": "node tasks/load_schema.js", diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index ddcaf2f68..94b15d7dd 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,5 +1,11 @@ var request = require('request'); +var base_url = "http://localhost:3000/movies/" describe("Endpoints under /movies", function() { - + it('responds with a 200 status code', function (done) { + request.get(base_url, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }) }) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index 44edc4388..7cf37f347 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -4,14 +4,19 @@ var db = app.get('db') var Movie = require('../../models/customer') describe('Customer', function () { + beforeEach(function(){ + + }) afterEach(function () { db.end() }) - describe('', function () { - + describe('Customer.all', function () { + it('should return an array', function(done) { + }) + }) }) -} + diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index ae4773df1..32bf3ed17 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -14,8 +14,19 @@ describe('Movie', function () { }) describe('all', function () { - + it('should return an array',function(done){ + Movie.all(function(error,movies){ + expect(movies).toEqual(jasmine.any(Array)) + done() + }) + }) + it('should contain movie objects',function(done){ + Movie.all(function(error,movies){ + expect(movies[0]).toContain("soemhting") + done() + }) + }) }) -} +}) diff --git a/spec/models/rental.spec.js b/spec/models/rental.spec.js index a18487ee2..66af89696 100644 --- a/spec/models/rental.spec.js +++ b/spec/models/rental.spec.js @@ -14,4 +14,4 @@ describe('Rental', function () { }) -} +}) From 3ab327e97d147d7e2de9f0e3336619c3f5f0e968 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 10:12:59 -0700 Subject: [PATCH 076/101] got rid of consolge.log --- models/customer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/customer.js b/models/customer.js index 34505c185..823445f15 100644 --- a/models/customer.js +++ b/models/customer.js @@ -72,7 +72,6 @@ Customer.rentedThisMovie = function(input, callback) { Customer.currentlyCheckedOut = function (input,callback) { // var order = input.shift() db.run("SELECT customers.name, checkout_date, due_date, movies.title FROM (SELECT customer_id, due_date, checkout_date, movie_id FROM rentals WHERE status='checked_out' OR status='overdue') as checkout INNER JOIN customers ON (checkout.customer_id = customers.id) INNER JOIN movies ON (checkout.movie_id = movies.id) WHERE movies.title=$1;",input, function (error, customers) { - console.log("halp") if(error || !customers) { callback(error || new Error("Could not retrieve rentals"), undefined); } else { @@ -84,4 +83,5 @@ Customer.currentlyCheckedOut = function (input,callback) { } + module.exports = Customer From dafbb147b2221993045aba2797c13466fcf3e378 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 10:13:31 -0700 Subject: [PATCH 077/101] added coverage script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 57c3c81fc..ab7f6d2aa 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "db:create": "createdb cassettecollection_development; createdb cassettecollection_test", "db:schema": "node tasks/load_schema.js", "db:seed": "node tasks/seed_data.js", - "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed" + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", + "coverage": "open coverage/lcov-report/index.html" }, "dependencies": { "body-parser": "~1.13.2", From 7c20efbf2ea8b04bd71401325ce2a90356b0d171 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 10:14:04 -0700 Subject: [PATCH 078/101] added tests for customers.all --- spec/models/customer.spec.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index 7cf37f347..553800c03 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -1,7 +1,7 @@ var app = require('../../app') var db = app.get('db') -var Movie = require('../../models/customer') +var Customer = require('../../models/customer') describe('Customer', function () { beforeEach(function(){ @@ -12,11 +12,24 @@ describe('Customer', function () { db.end() }) - describe('Customer.all', function () { + describe('.all', function () { it('should return an array', function(done) { + Customer.all(function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + + }) + it('be at least certain size', function(done) { + Customer.all(function(error,customers){ + expect(customers.length).toBeGreaterThan(199) + done() }) + }) + }) +}) From 1eaf8a952a7d80900276d237b7579179ae230525 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 10:15:10 -0700 Subject: [PATCH 079/101] something happened to npm-debug log --- npm-debug.log | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 90ab790c4..000000000 --- a/npm-debug.log +++ /dev/null @@ -1,49 +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 'test' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'pretest', 'test', 'posttest' ] -5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing -7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Nadine/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Users/Nadine/.rvm/gems/ruby-2.3.0/bin:/Users/Nadine/.rvm/gems/ruby-2.3.0@global/bin:/Users/Nadine/.rvm/rubies/ruby-2.3.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/Nadine/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/Nadine/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', -11 silly lifecycle 'clear; ./node_modules/.bin/istanbul cover -x \'spec/**/*\' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] -12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script -14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -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/Nadine/C5/projects/VideoStoreAPI -17 error Darwin 15.0.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" -19 error node v6.2.1 -20 error npm v3.9.3 -21 error code ELIFECYCLE -22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. -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_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ -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 a927554fb993eac7e7b461654b152d40c8a8696a Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 11:26:15 -0700 Subject: [PATCH 080/101] added tests for sortby, customerswithmovie, and rentedthismovie functions --- spec/models/customer.spec.js | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index 553800c03..6625090f9 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -30,6 +30,57 @@ describe('Customer', function () { }) }) + + describe('.sortBy', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Customer.sortBy(['postal_code',1,20],function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain size', function(done) { + Customer.sortBy(['name',1,20], function(error,customers){ + expect(customers.length).toEqual(20) + done() + }) + }) + }) + + describe('.customersWithMovie', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Customer.customersWithMovie(['Jaws'],function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain size', function(done) { + Customer.customersWithMovie(['Psycho'], function(error,customers){ + expect(customers.length).toEqual(1) + done() + }) + }) + }) + + describe('.rentedThisMovie', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Customer.rentedThisMovie(['Jaws', 'checkout_date'], function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain size', function(done) { + Customer.rentedThisMovie(['Psycho', 'name'], function(error,customers){ + expect(customers.length).toEqual(3) + done() + }) + }) + }) }) From cb9bc25f7c6011ca157c1234fa045fce401132bf Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 11:29:10 -0700 Subject: [PATCH 081/101] added test for currentlycheckedout function --- spec/models/customer.spec.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index 6625090f9..844d80a39 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -81,6 +81,23 @@ describe('Customer', function () { }) }) }) + + describe('.currentlyCheckedOut', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Customer.currentlyCheckedOut(['Jaws'], function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain size', function(done) { + Customer.currentlyCheckedOut(['Psycho'], function(error,customers){ + expect(customers.length).toEqual(1) + done() + }) + }) + }) }) From 0b93732ae08a9cc1e09649cc7ff6c36db415b6df Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 11:42:43 -0700 Subject: [PATCH 082/101] added error tests for sortby and customers with movie. reached 90%cov for customers model --- spec/models/customer.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index 844d80a39..e0b01597a 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -46,6 +46,13 @@ describe('Customer', function () { done() }) }) + + it('produces an error when it doesnt recognize a column', function(done) { + Customer.sortBy(['imanerror',1,20], function(error,customers){ + expect(error.message).toEqual('column "imanerror" does not exist') + done() + }) + }) }) describe('.customersWithMovie', function () { @@ -63,6 +70,14 @@ describe('Customer', function () { done() }) }) + + it('returns an error if no input', function(done) { + Customer.customersWithMovie([], function(error,customers){ + expect(customers).toEqual(undefined) + expect(error).toNotEqual(null) + done() + }) + }) }) describe('.rentedThisMovie', function () { From b308127fd97bbe4f0ea16a63e60cf9fc9d46358e Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 23 Jun 2016 12:38:23 -0700 Subject: [PATCH 083/101] Movie Model tests at 73%; --- controllers/movies.js | 51 +++++++++++++++++----------------- models/movie.js | 3 +- spec/models/movie.spec.js | 58 +++++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/controllers/movies.js b/controllers/movies.js index de70434c5..33a6d1347 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -2,30 +2,31 @@ var Movie = require("../models/movie") var Customer = require("../models/customer") var MoviesController = { - index: function(req, res, next) { + index: function (req, res, next) { Movie.all(function(error, movies) { - if(error) { - var err = new Error("Error retrieving customer list:\n" + error.message); - err.status = 500; - next(err); + if (error) { + var err = new Error("Error retrieving customer list:\n" + error.message) + err.status = 500 + next(err) } else { res.json(movies) } - }); + }) }, - sortBy: function(req, res, next) { + sortBy: function (req, res, next) { var type = req.params.query var n = req.query.n var p = req.query.p - var firstrow = n*(p-1)+1 - var lastrow = n*p - console.log("bla",type,firstrow,lastrow) - Movie.sortBy([type,firstrow,lastrow],function(error, movies) { - if(error) { - var err = new Error("Error retrieving customer list:\n" + error.message); - err.status = 500; - next(err); + console.log("dese ", type, n, p) + var firstrow = n * (p - 1) + 1 + var lastrow = n * p + console.log("bla", type, firstrow, lastrow) + Movie.sortBy([type, firstrow, lastrow], function (error, movies) { + if (error) { + var err = new Error("Error retrieving customer list:\n" + error.message) + err.status = 500 + next(err) } else { res.json(movies) } @@ -33,11 +34,11 @@ var MoviesController = { current: function (req, res, next) { var title = req.params.movie - Customer.customersWithMovie([title], function(error, movies) { - if(error) { - var err = new Error("Error retrieving customer list:\n" + error.message); - err.status = 500; - next(err); + Customer.customersWithMovie([title], function (error, movies) { + if (error) { + var err = new Error("Error retrieving customer list:\n" + error.message) + err.status = 500 + next(err) } else { res.json(movies) } @@ -46,11 +47,11 @@ var MoviesController = { sortedHistory: function (req, res, next) { var title = req.params.movie var sort = req.params.by - Customer.rentedThisMovie([title, sort], function(error, movies) { - if(error) { - var err = new Error("Error retrieving customer list:\n" + error.message); - err.status = 500; - next(err); + Customer.rentedThisMovie([title, sort], function (error, movies) { + if (error) { + var err = new Error("Error retrieving customer list:\n" + error.message) + err.status = 500 + next(err) } else { res.json(movies) } diff --git a/models/movie.js b/models/movie.js index 6a3d70e50..a008b2a22 100644 --- a/models/movie.js +++ b/models/movie.js @@ -29,6 +29,7 @@ Movie.all = function(callback) { Movie.sortBy = function(input, callback){ var order = input.shift() db.run("Select * From (Select Row_Number() Over (Order By " + order + ") As RowNum, *From movies) movies Where RowNum BETWEEN $1 AND $2;",input, function(error, movies) { + // console.log("luff ", movies) if(error || !movies) { callback(error || new Error("Could not retrieve Movies"), undefined); } else { @@ -51,4 +52,4 @@ Movie.rentalInfo = function(input, callback) { }); }; -module.exports = Movie \ No newline at end of file +module.exports = Movie diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index 32bf3ed17..b0f61e350 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -14,16 +14,64 @@ describe('Movie', function () { }) describe('all', function () { - it('should return an array',function(done){ - Movie.all(function(error,movies){ + it('should not be null', function (done) { + Movie.all(function (error, movies) { + expect(movies).toNotBe(null) + done() + }) + }) + + it('should return an array', function (done) { + Movie.all(function (error, movies) { expect(movies).toEqual(jasmine.any(Array)) done() }) }) - it('should contain movie objects',function(done){ - Movie.all(function(error,movies){ - expect(movies[0]).toContain("soemhting") + it('should contain movie objects', function (done) { + Movie.all(function (error, movies) { + expect(movies[0]).toEqual(jasmine.any(Movie)) + done() + }) + }) + + it('should contain all movies that exist in the database', function (done) { + Movie.all(function (error, movies) { + expect(movies.length).toEqual(100) + done() + }) + }) + }) + + describe('sortBy', function () { + var firstAlphabeticalMovieTitle = "12 Angry Men" + var firstReleaseDate = "1923-04-01" + + it('should return an array', function (done) { + Movie.sortBy(['title', 1, 10], function (error, movies) { + expect(movies).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('should contain movie objects', function (done) { + Movie.sortBy(['title', 2, 12], function (error, movies) { + expect(movies[0]).toEqual(jasmine.any(Movie)) + done() + }) + }) + + it('should be able to sort by name', function (done) { + Movie.sortBy(['title', 1, 25], function (error, movies) { + expect(movies[0].title).toEqual(firstAlphabeticalMovieTitle) + done() + }) + }) + + it('should be able to sort by release_date', function (done) { + Movie.sortBy(['release_date', 1, 15], function (error, movies) { + console.log("halp ", movies) + expect(movies[0].release).toEqual(firstReleaseDate) done() }) }) From d1f14ac01a4d8541863e626a9d3ee2803d18f967 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 13:51:54 -0700 Subject: [PATCH 084/101] added currentcheckedout function tests --- spec/models/rental.spec.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/spec/models/rental.spec.js b/spec/models/rental.spec.js index 66af89696..b3414fa02 100644 --- a/spec/models/rental.spec.js +++ b/spec/models/rental.spec.js @@ -1,7 +1,7 @@ var app = require('../../app') var db = app.get('db') -var Movie = require('../../models/rental') +var Rental = require('../../models/rental') describe('Rental', function () { @@ -9,9 +9,37 @@ describe('Rental', function () { db.end() }) - describe('', function () { - + describe('.currentCheckedOut', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Rental.currentCheckedOut([55,'checked_out'], function(error,rentals){ + expect(rentals).toEqual(jasmine.any(Array)) + done() + }) + }) + it('be a certain size', function(done) { + Rental.currentCheckedOut([4,'checked_out'], function(error,rentals){ + expect(rentals.length).toEqual(2) + done() + }) + }) }) + describe('.currentCheckedOut', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Rental.currentCheckedOut([55,'checked_out'], function(error,rentals){ + expect(rentals).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain size', function(done) { + Rental.currentCheckedOut([4,'checked_out'], function(error,rentals){ + expect(rentals.length).toEqual(2) + done() + }) + }) + }) }) From 3a9f1099a215e928d58049700ae43e6233ffb0f8 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 14:11:23 -0700 Subject: [PATCH 085/101] added tests for the rest of rental functions --- spec/models/movie.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index 32bf3ed17..50bc90800 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -21,12 +21,12 @@ describe('Movie', function () { }) }) - it('should contain movie objects',function(done){ - Movie.all(function(error,movies){ - expect(movies[0]).toContain("soemhting") - done() - }) - }) + // it('should contain movie objects',function(done){ + // Movie.all(function(error,movies){ + // expect(movies[0]).toContain("soemhting") + // done() + // }) + // }) }) }) From 4d0d87ea881299287ca98b4a64f8b07b1e484d8a Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 23 Jun 2016 15:22:09 -0700 Subject: [PATCH 086/101] Movies model is 90% covered; --- models/movie.js | 2 +- spec/models/movie.spec.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/models/movie.js b/models/movie.js index a008b2a22..c8ac29229 100644 --- a/models/movie.js +++ b/models/movie.js @@ -41,7 +41,7 @@ Movie.sortBy = function(input, callback){ }; Movie.rentalInfo = function(input, callback) { - db.run("SELECT overview, release_date, inventory, (inventory - (SELECT count(*)FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id AND status='checked_out')) as available_inventory FROM movies WHERE title = $1;",input, function(error, movie) { + db.run("SELECT title, overview, release_date, inventory, (inventory - (SELECT count(*)FROM rentals WHERE (SELECT id FROM movies WHERE movies.title = $1) = movie_id AND status='checked_out')) as available_inventory FROM movies WHERE title = $1;",input, function(error, movie) { if(error || !movie) { callback(error || new Error("Could not retrieve movie info"), undefined); } else { diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index b0f61e350..f5cbaf74c 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -70,11 +70,42 @@ describe('Movie', function () { it('should be able to sort by release_date', function (done) { Movie.sortBy(['release_date', 1, 15], function (error, movies) { - console.log("halp ", movies) expect(movies[0].release).toEqual(firstReleaseDate) done() }) }) }) + describe('rentalInfo', function () { + + it('should return an array', function (done) { + Movie.rentalInfo([title], function (error, movies) { + expect(movies).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('should contain movie objects', function (done) { + Movie.rentalInfo([title], function (error, movies) { + expect(movies[0]).toEqual(jasmine.any(Movie)) + done() + }) + }) + + it('should find the correct movie', function (done) { + Movie.rentalInfo(["Psycho"], function (error, movies) { + console.log("yo ", movies[0]) + expect(movies[0].title).toEqual("Psycho") + done() + }) + }) + + it('should only return one movie', function (done) { + Movie.rentalInfo([title], function (error, movies) { + expect(movies.length).toEqual(1) + done() + }) + }) + }) + }) From c73ca4e7d4141e1cacb73a550d513352824624f0 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 15:26:43 -0700 Subject: [PATCH 087/101] added empty files for controller testing --- spec/controllers/customers.spec.js | 0 spec/controllers/rentals.spec.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/controllers/customers.spec.js create mode 100644 spec/controllers/rentals.spec.js diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js new file mode 100644 index 000000000..e69de29bb diff --git a/spec/controllers/rentals.spec.js b/spec/controllers/rentals.spec.js new file mode 100644 index 000000000..e69de29bb From e9f073ca170f3d4350e08c07f0c1ff12949f384d Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 15:26:58 -0700 Subject: [PATCH 088/101] finish up rentas --- spec/models/rental.spec.js | 56 ++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/spec/models/rental.spec.js b/spec/models/rental.spec.js index b3414fa02..78c4f6c51 100644 --- a/spec/models/rental.spec.js +++ b/spec/models/rental.spec.js @@ -20,24 +20,70 @@ describe('Rental', function () { it('be a certain size', function(done) { Rental.currentCheckedOut([4,'checked_out'], function(error,rentals){ - expect(rentals.length).toEqual(2) + expect(rentals.length).toBeGreaterThan(1) done() }) }) }) - describe('.currentCheckedOut', function () { + describe('.all', function () { // input should be [order, firstrow, lastrow] it('should return an array', function(done) { - Rental.currentCheckedOut([55,'checked_out'], function(error,rentals){ + Rental.all([55], function(error,rentals){ expect(rentals).toEqual(jasmine.any(Array)) done() }) }) it('be a certain size', function(done) { - Rental.currentCheckedOut([4,'checked_out'], function(error,rentals){ - expect(rentals.length).toEqual(2) + Rental.all([4], function(error,rentals){ + expect(rentals.length).toBeGreaterThan(3) + done() + }) + }) + + it('returns an error if no input', function(done) { + Rental.all([], function(error,rentals){ + console.log(error, rentals) + expect(rentals).toEqual(undefined) + expect(error).toNotEqual(null) + done() + }) + }) + }) + + describe('.overdueList', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Rental.overdueList(function(error,rentals){ + expect(rentals).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain size', function(done) { + Rental.overdueList(function(error,rentals){ + expect(rentals.length).toEqual(1) + done() + }) + }) + }) + + describe('.checkOut', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Rental.checkOut(['Jaws', 4], function(error,rentals){ + expect(rentals).toEqual(jasmine.any(Array)) + done() + }) + }) + }) + + describe('.return', function () { + // input should be [order, firstrow, lastrow] + it('should return an array', function(done) { + Rental.return(['Jaws', 4], function(error,rentals){ + expect(rentals).toEqual(jasmine.any(Array)) done() }) }) From 15290c3b0ea4c9513e98ff4c99de2e0bdc3cbeef Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 16:46:23 -0700 Subject: [PATCH 089/101] added tests for index and sortby function --- spec/controllers/customers.spec.js | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index e69de29bb..756de036f 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -0,0 +1,64 @@ +var request = require('request') +var app = require("../../app.js") +var base_url = "http://localhost:3000/customers" + +describe("CustomersController", function(){ + + describe("#index", function(done){ + it("returns a success response", function(done){ + request.get(base_url, function(error, response, body){ + expect(response.statusCode).toBe(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("returns customer information", function(done){ + request.get(base_url, function(error, response, body){ + var data = JSON.parse(body) + console.log(data, typeof data) + expect(Object.keys(data[4])).toEqual(["id", "name", "registered_at", "postal_code", "phone", "account_credit"]) + done() + }) + }) + }) + + describe("#sortBy", function(done){ + it("returns a success response", function(done){ + request.get(base_url+"/sort/name?n=10&p=2", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url+"/sort/name?n=10&p=2", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + it("returns customer information", function(done){ + request.get(base_url+"/sort/name?n=10&p=2", function(error, response, body){ + var data = JSON.parse(body) + expect(Object.keys(data[0])).toEqual(["id", "name", "registered_at", "postal_code", "phone", "account_credit"]) + done() + }) + }) + + it("returns the correct number of rows", function(done){ + request.get(base_url+"/sort/name?n=22&p=2", function(error, response, body){ + var data = JSON.parse(body) + console.log(data, typeof data) + expect(data.length).toEqual(22) + done() + }) + }) + }) +}) From 036b3486b7750d4dec54f8bf686c9253ff079688 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 16:46:48 -0700 Subject: [PATCH 090/101] got rid of console.log --- spec/models/movie.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index f5cbaf74c..620a6cd6d 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -94,7 +94,6 @@ describe('Movie', function () { it('should find the correct movie', function (done) { Movie.rentalInfo(["Psycho"], function (error, movies) { - console.log("yo ", movies[0]) expect(movies[0].title).toEqual("Psycho") done() }) From 81166353790492f951ea3b126ce9e2258fd0af24 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 16:47:06 -0700 Subject: [PATCH 091/101] got rid of console.log --- models/rental.js | 1 - 1 file changed, 1 deletion(-) diff --git a/models/rental.js b/models/rental.js index 3e551a91b..7fa0322f6 100644 --- a/models/rental.js +++ b/models/rental.js @@ -39,7 +39,6 @@ Rental.all = function (input,callback) { Rental.overdueList = function (callback) { db.run("SELECT customers.name, movies.title, checkout_date, due_date FROM (SELECT customer_id, movie_id, due_date, checkout_date FROM rentals WHERE status='overdue') as overdues INNER JOIN customers ON (overdues.customer_id = customers.id) INNER JOIN movies ON (overdues.movie_id = movies.id);", function (error, rentals) { - console.log("halp") if(error || !rentals) { callback(error || new Error("Could not retrieve rentals"), undefined); } else { From 0b867fe1226447d2868db67b96aebe896b344ad7 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Thu, 23 Jun 2016 16:47:47 -0700 Subject: [PATCH 092/101] got rid of console.logs --- controllers/customers.js | 1 - controllers/movies.js | 2 -- controllers/rentals.js | 7 ++----- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/controllers/customers.js b/controllers/customers.js index 4ffcf46cd..d58a91327 100644 --- a/controllers/customers.js +++ b/controllers/customers.js @@ -20,7 +20,6 @@ var CustomersController = { var p = req.query.p var firstrow = n*(p-1)+1 var lastrow = n*p - console.log("bla",type,firstrow,lastrow) Customer.sortBy([type,firstrow,lastrow],function(error, customers) { if(error) { var err = new Error("Error retrieving customer list:\n" + error.message); diff --git a/controllers/movies.js b/controllers/movies.js index 33a6d1347..392f38987 100644 --- a/controllers/movies.js +++ b/controllers/movies.js @@ -18,10 +18,8 @@ var MoviesController = { var type = req.params.query var n = req.query.n var p = req.query.p - console.log("dese ", type, n, p) var firstrow = n * (p - 1) + 1 var lastrow = n * p - console.log("bla", type, firstrow, lastrow) Movie.sortBy([type, firstrow, lastrow], function (error, movies) { if (error) { var err = new Error("Error retrieving customer list:\n" + error.message) diff --git a/controllers/rentals.js b/controllers/rentals.js index 22b8e6125..5cd7243fd 100644 --- a/controllers/rentals.js +++ b/controllers/rentals.js @@ -34,7 +34,7 @@ var RentalsController = { checkOut: function (req, res, next) { var title = req.params.movie var id = 55 - console.log(req.body.customer_id) // need to test to see if customer's id comes in body + // need to test to see if customer's id comes in body // if we don't want to have them passed in the body we can alter the url to take a // second parameter ->/rentals/:movie/check-out/:cust_id @@ -52,7 +52,7 @@ var RentalsController = { return: function (req, res, next) { var title = req.params.movie var id = 55 - console.log(req.body.customer_id) // need to test to see if customer's id comes in body + // need to test to see if customer's id comes in body Rental.return([title, id],function (error, rental) { if(error) { @@ -66,9 +66,6 @@ var RentalsController = { }, overdue: function (req, res, next) { - - console.log("ohs ") - Rental.overdueList(function (error, rentals) { if(error) { var err = new Error("Error retrieving overdue list:\n" + error.message); From c8ded502939a504848d64f55ff7ca6487ed29921 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 23 Jun 2016 19:39:45 -0700 Subject: [PATCH 093/101] Tested bad request; --- spec/models/movie.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/models/movie.spec.js b/spec/models/movie.spec.js index 620a6cd6d..5a0d755f9 100644 --- a/spec/models/movie.spec.js +++ b/spec/models/movie.spec.js @@ -74,6 +74,13 @@ describe('Movie', function () { done() }) }) + + it('returns an empty array when the given an invalid sort type', function (done) { + Movie.sortBy(['year', 3, 15], function (error, movies) { + expect(movies).toEqual(undefined) + done() + }) + }) }) describe('rentalInfo', function () { @@ -105,6 +112,13 @@ describe('Movie', function () { done() }) }) + + it('returns an empty array when it does not find the movie title', function (done) { + Movie.rentalInfo(["Mr. Nobody"], function (error, movies) { + expect(movies).toEqual([]) + done() + }) + }) }) }) From 963dfb322db7fc207c0ca3b30253b23432b22c43 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 23 Jun 2016 19:40:06 -0700 Subject: [PATCH 094/101] Commented out console.logs; --- spec/controllers/customers.spec.js | 4 ++-- spec/models/rental.spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 756de036f..853a2cfcf 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -22,7 +22,7 @@ describe("CustomersController", function(){ it("returns customer information", function(done){ request.get(base_url, function(error, response, body){ var data = JSON.parse(body) - console.log(data, typeof data) + // console.log(data, typeof data) expect(Object.keys(data[4])).toEqual(["id", "name", "registered_at", "postal_code", "phone", "account_credit"]) done() }) @@ -55,7 +55,7 @@ describe("CustomersController", function(){ it("returns the correct number of rows", function(done){ request.get(base_url+"/sort/name?n=22&p=2", function(error, response, body){ var data = JSON.parse(body) - console.log(data, typeof data) + // console.log(data, typeof data) expect(data.length).toEqual(22) done() }) diff --git a/spec/models/rental.spec.js b/spec/models/rental.spec.js index 78c4f6c51..7acfd26af 100644 --- a/spec/models/rental.spec.js +++ b/spec/models/rental.spec.js @@ -44,7 +44,7 @@ describe('Rental', function () { it('returns an error if no input', function(done) { Rental.all([], function(error,rentals){ - console.log(error, rentals) + // console.log(error, rentals) expect(rentals).toEqual(undefined) expect(error).toNotEqual(null) done() From 244eb6ffd22e3d96adb60c58f319dd5776f8d73e Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 23 Jun 2016 21:22:24 -0700 Subject: [PATCH 095/101] Added some movie controller tests; --- npm-debug.log | 49 +++++++++++++++++++++++++++++++++ spec/controllers/movies.spec.js | 22 +++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 000000000..a2fdd949a --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,49 @@ +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 'test' ] +2 info using npm@3.9.3 +3 info using node@v6.2.1 +4 verbose run-script [ 'pretest', 'test', 'posttest' ] +5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 +6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing +7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 +8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true +9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/sophia/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/sophia/.rvm/gems/ruby-2.3.0/bin:/Users/sophia/.rvm/gems/ruby-2.3.0@global/bin:/Users/sophia/.rvm/rubies/ruby-2.3.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/sophia/.rvm/bin:/Users/sophia/.rvm/bin +10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/sophia/C5/projects/VideoStoreAPI +11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', +11 silly lifecycle 'clear; ./node_modules/.bin/istanbul cover -x \'spec/**/*\' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] +12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null +13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script +14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` +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/sophia/C5/projects/VideoStoreAPI +17 error Darwin 13.4.0 +18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" +19 error node v6.2.1 +20 error npm v3.9.3 +21 error code ELIFECYCLE +22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` +22 error Exit status 1 +23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. +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_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ +23 error You can get information on how to open an issue for this project with: +23 error npm bugs video-store-api +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls video-store-api +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 94b15d7dd..d07c6f53e 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -8,4 +8,26 @@ describe("Endpoints under /movies", function() { done() }) }) + + it('returns a body of content', function (done) { + request.get(base_url, function(error, response, body) { + expect(body).toNotBe(null) + done() + }) + }) + + it('returns json', function (done) { + request.get(base_url, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + describe('/movies/sort/') + it('returns json', function (done) { + request.get(base_url, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) }) From 13877176c798863d34a36fa3e350b2901060e2b8 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 24 Jun 2016 09:48:13 -0700 Subject: [PATCH 096/101] got rid of console.log in customers and added 2 function tests in rentals and 1 in movies --- spec/controllers/customers.spec.js | 2 -- spec/controllers/movies.spec.js | 25 ++++++++++++++------ spec/controllers/rentals.spec.js | 38 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 756de036f..7c7624500 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -22,7 +22,6 @@ describe("CustomersController", function(){ it("returns customer information", function(done){ request.get(base_url, function(error, response, body){ var data = JSON.parse(body) - console.log(data, typeof data) expect(Object.keys(data[4])).toEqual(["id", "name", "registered_at", "postal_code", "phone", "account_credit"]) done() }) @@ -55,7 +54,6 @@ describe("CustomersController", function(){ it("returns the correct number of rows", function(done){ request.get(base_url+"/sort/name?n=22&p=2", function(error, response, body){ var data = JSON.parse(body) - console.log(data, typeof data) expect(data.length).toEqual(22) done() }) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 94b15d7dd..6e2781625 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,11 +1,22 @@ -var request = require('request'); -var base_url = "http://localhost:3000/movies/" +var request = require('request') +var app = require("../../app.js") +var base_url = "http://localhost:3000/movies" -describe("Endpoints under /movies", function() { - it('responds with a 200 status code', function (done) { - request.get(base_url, function(error, response, body) { - expect(response.statusCode).toEqual(200) - done() +describe("RentalsController", function(){ + + describe("#index", function(done){ + it("returns a success response", function(done){ + request.get(base_url, function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url, function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) }) }) }) diff --git a/spec/controllers/rentals.spec.js b/spec/controllers/rentals.spec.js index e69de29bb..1360824b6 100644 --- a/spec/controllers/rentals.spec.js +++ b/spec/controllers/rentals.spec.js @@ -0,0 +1,38 @@ +var request = require('request') +var app = require("../../app.js") +var base_url = "http://localhost:3000/rentals" + +describe("RentalsController", function(){ + + describe("#overdue", function(done){ + it("returns a success response", function(done){ + request.get(base_url+"/overdue", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url+"/overdue", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) + + describe("#lookupMovie", function(done){ + it("returns a success response", function(done){ + request.get(base_url+"/Jaws", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url+"/Jaws", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) +}) \ No newline at end of file From 54f7921fc0807f954d7b54045fdddf5048681d33 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 24 Jun 2016 09:57:15 -0700 Subject: [PATCH 097/101] Movies Controller tests; --- spec/controllers/movies.spec.js | 57 ++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index d07c6f53e..c8cc83617 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -23,11 +23,58 @@ describe("Endpoints under /movies", function() { }) }) - describe('/movies/sort/') - it('returns json', function (done) { - request.get(base_url, function(error, response, body) { - expect(response.headers['content-type']).toContain('application/json') - done() + describe('/movies/sort/', function () { + var goodSort = 'sort/release_date?n=5&p=1' + var badSort = 'sort/year?n=5&p1' + + it('responds with 200 for a good request', function (done) { + request.get(base_url + goodSort, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }) + + it('returns json', function (done) { + request.get(base_url + goodSort, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + it('responds with 500 for a bad request', function (done) { + request.get(base_url + badSort, function(error, response, body) { + expect(response.statusCode).toEqual(500) + done() + }) + }) + + }) + + describe('/movies/:title/current', function () { + var goodCurrent = 'Psycho/current' + var badCurrent = 'Young%20Frankenstein/current' + + it('responds with 200 for a good request', function (done) { + request.get(base_url + goodCurrent, function(error, response, body) { + expect(response.statusCode).toEqual(200) + done() + }) + }) + + it('returns json', function (done) { + request.get(base_url + goodCurrent, function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + it('responds with empty array for bad request', function (done) { + request.get(base_url + badCurrent, function(error, response, body) { + expect(response).toEqual([]) + done() + }) }) + }) + }) From 4c4c4e21b93624014cf52251b9d19bdf6d479ffa Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 24 Jun 2016 09:57:47 -0700 Subject: [PATCH 098/101] Worked on json docs; --- docs.json | 21 +++------------------ npm-debug.log | 49 ------------------------------------------------- 2 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 npm-debug.log diff --git a/docs.json b/docs.json index 5dd5f4619..d9bc536ac 100644 --- a/docs.json +++ b/docs.json @@ -1,22 +1,6 @@ -/*p The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. - -p The API endpoint is available at https://cassettecollection.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL. - -h2 API Specification - -p This is version 1 of the Cassette Collection. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/. - -h3 Search for suggestions - -Search for food and music suggestions given a particular search term, and an optional limit for number of results. - -h4 Request - -Search requests are GET requests to the /v1/suggestions/search endpoint with the following parameters:*/ - [ - "CassetteCollection": "The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. The API endpoint is available at https://tunes-takeout-api.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL.", - "API_Specification": + {"CassetteCollection": "The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. The API endpoint is available at https://tunes-takeout-api.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL."}, + {"API_Specification": [ "Request": "This is version 1 of the Tunes & Takeout API. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/.", "Response": "Search results are JSON documents containing a list of suggestion hashes, and a canonical URL for the request itself. Each suggestion hash includes the ID for a specific business from the Yelp API as well as an ID and type for an item from the Spotify API. @@ -27,4 +11,5 @@ Search requests are GET requests to the /v1/suggestions/search endpoint with the If the request was not successful, the following HTTP status codes may be returned depending on the specific error: 400 - The request parameters were invalid. Either the query was missing, or the limit was not an integer between 1 and 100." + ]} ] diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index a2fdd949a..000000000 --- a/npm-debug.log +++ /dev/null @@ -1,49 +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 'test' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'pretest', 'test', 'posttest' ] -5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing -7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/sophia/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/sophia/.rvm/gems/ruby-2.3.0/bin:/Users/sophia/.rvm/gems/ruby-2.3.0@global/bin:/Users/sophia/.rvm/rubies/ruby-2.3.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/sophia/.rvm/bin:/Users/sophia/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/sophia/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', -11 silly lifecycle 'clear; ./node_modules/.bin/istanbul cover -x \'spec/**/*\' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] -12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script -14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -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/sophia/C5/projects/VideoStoreAPI -17 error Darwin 13.4.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" -19 error node v6.2.1 -20 error npm v3.9.3 -21 error code ELIFECYCLE -22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. -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_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ -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 562f888b19c415c82658233bb6a60a258a0794b8 Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 24 Jun 2016 11:29:50 -0700 Subject: [PATCH 099/101] adding --- npm-debug.log | 49 ------------------------------ spec/controllers/customers.spec.js | 4 --- spec/controllers/movies.spec.js | 41 ------------------------- 3 files changed, 94 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index a2fdd949a..000000000 --- a/npm-debug.log +++ /dev/null @@ -1,49 +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 'test' ] -2 info using npm@3.9.3 -3 info using node@v6.2.1 -4 verbose run-script [ 'pretest', 'test', 'posttest' ] -5 info lifecycle video-store-api@0.0.0~pretest: video-store-api@0.0.0 -6 silly lifecycle video-store-api@0.0.0~pretest: no script for pretest, continuing -7 info lifecycle video-store-api@0.0.0~test: video-store-api@0.0.0 -8 verbose lifecycle video-store-api@0.0.0~test: unsafe-perm in lifecycle true -9 verbose lifecycle video-store-api@0.0.0~test: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/sophia/C5/projects/VideoStoreAPI/node_modules/.bin:/usr/local/Cellar/node/6.2.1/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/sophia/.rvm/gems/ruby-2.3.0/bin:/Users/sophia/.rvm/gems/ruby-2.3.0@global/bin:/Users/sophia/.rvm/rubies/ruby-2.3.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Users/sophia/.rvm/bin:/Users/sophia/.rvm/bin -10 verbose lifecycle video-store-api@0.0.0~test: CWD: /Users/sophia/C5/projects/VideoStoreAPI -11 silly lifecycle video-store-api@0.0.0~test: Args: [ '-c', -11 silly lifecycle 'clear; ./node_modules/.bin/istanbul cover -x \'spec/**/*\' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/' ] -12 silly lifecycle video-store-api@0.0.0~test: Returned: code: 1 signal: null -13 info lifecycle video-store-api@0.0.0~test: Failed to exec test script -14 verbose stack Error: video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -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/sophia/C5/projects/VideoStoreAPI -17 error Darwin 13.4.0 -18 error argv "/usr/local/Cellar/node/6.2.1/bin/node" "/usr/local/bin/npm" "run" "test" -19 error node v6.2.1 -20 error npm v3.9.3 -21 error code ELIFECYCLE -22 error video-store-api@0.0.0 test: `clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/` -22 error Exit status 1 -23 error Failed at the video-store-api@0.0.0 test script 'clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/'. -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_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/ -23 error You can get information on how to open an issue for this project with: -23 error npm bugs video-store-api -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls video-store-api -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 77c14cde4..7c7624500 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -22,10 +22,6 @@ describe("CustomersController", function(){ it("returns customer information", function(done){ request.get(base_url, function(error, response, body){ var data = JSON.parse(body) -<<<<<<< HEAD -======= - // console.log(data, typeof data) ->>>>>>> 244eb6ffd22e3d96adb60c58f319dd5776f8d73e expect(Object.keys(data[4])).toEqual(["id", "name", "registered_at", "postal_code", "phone", "account_credit"]) done() }) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index 3fc0af541..f431066d1 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,44 +1,3 @@ var request = require('request') var app = require("../../app.js") var base_url = "http://localhost:3000/movies" - -describe("RentalsController", function(){ - - describe("#index", function(done){ - it("returns a success response", function(done){ - request.get(base_url, function(error, response, body){ - expect(response.statusCode).toBe(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('returns a body of content', function (done) { - request.get(base_url, function(error, response, body) { - expect(body).toNotBe(null) - done() - }) - }) - - it('returns json', function (done) { - request.get(base_url, function(error, response, body) { - expect(response.headers['content-type']).toContain('application/json') - done() - }) - }) - - describe('/movies/sort/') - it('returns json', function (done) { - request.get(base_url, function(error, response, body) { - expect(response.headers['content-type']).toContain('application/json') - done() - }) - }) -}) From 1ab0578cfab6985caf118a55700119590fd35e4f Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 24 Jun 2016 11:43:07 -0700 Subject: [PATCH 100/101] Worked on docs; --- controllers/api.js | 13 +++++++ docs.json | 55 ++++++++++++++++++++++++------ package.json | 1 + routes/index.js | 10 +++--- views/docs.ejs | 15 ++++++++ views/{docs.jade => jadedocs.jade} | 0 6 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 controllers/api.js create mode 100644 views/docs.ejs rename views/{docs.jade => jadedocs.jade} (100%) diff --git a/controllers/api.js b/controllers/api.js new file mode 100644 index 000000000..fa5a84f03 --- /dev/null +++ b/controllers/api.js @@ -0,0 +1,13 @@ +var docs = require('../docs.json') + +var ApiController = { + docs: function(req, res, next) { + res.render('jadedocs') + }, + + jsonDocs: function(req, res, next) { + res.json(docs) + } +} + +module.exports = ApiController diff --git a/docs.json b/docs.json index d9bc536ac..9e352e444 100644 --- a/docs.json +++ b/docs.json @@ -1,15 +1,50 @@ [ - {"CassetteCollection": "The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. The API endpoint is available at https://tunes-takeout-api.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL."}, - {"API_Specification": [ - "Request": "This is version 1 of the Tunes & Takeout API. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/.", - "Response": "Search results are JSON documents containing a list of suggestion hashes, and a canonical URL for the request itself. Each suggestion hash includes the ID for a specific business from the Yelp API as well as an ID and type for an item from the Spotify API. + { + "CassetteCollection": "The Tunes & Takeout API allows programmatic access to randomized suggestions of specific food and music pairings, that data for which is obtained from the Yelp and Spotify APIs. The API endpoint is available at https://tunes-takeout-api.herokuapp.com/ and all paths listed in this documentation should be assumed to use that base URL." + }, + { + "Customers": [ + { + "Request": "This is version 1 of the Tunes & Takeout API. To ensure consistency if the API evolves further, all requests to version 1 are prefixed with the path /v1/." + }, + { + "Response": "Search results are JSON documents containing a list of suggestion hashes, and a canonical URL for the request itself. Each suggestion hash includes the ID for a specific business from the Yelp API as well as an ID and type for an item from the Spotify API." + }, + { + "Example": [ + { + "Request URL": "/customers" + }, + { + "Response data": [ + { + "id": 1, + "name": "Shelley Rocha", + "registered_at": "Wed, 29 Apr 2015 07:54:14 -0700", + "postal_code": "24309", + "phone": "(322) 510-8695", + "account_credit": "13.15" + }, + { + "id": 2, + "name": "Curran Stout", + "registered_at": "Wed, 16 Apr 2014 21:40:20 -0700", + "postal_code": "94267", + "phone": "(908) 949-6758", + "account_credit": "35.66" + }, + { + "id": 3, + "name": "Roanna Robinson", + "registered_at": "Fri, 28 Nov 2014 13:14:08 -0800", + "postal_code": "15867", + "phone": "(323) 336-1841", + "account_credit": "50.39" + } + ]} + ] + } - Both IDs are string values, and the type for the music item is one of artist, album, track. - Wherever possible, the Tunes & Takeout API is written to provide consistent results for the same queries. This can aid with caching, but it cannot be guaranteed. Because the Tunes & Takeout API relies upon the Yelp and Spotify APIs, when their data changes the results of particular search queries may also change. - - If the request was not successful, the following HTTP status codes may be returned depending on the specific error: - - 400 - The request parameters were invalid. Either the query was missing, or the limit was not an integer between 1 and 100." ]} ] diff --git a/package.json b/package.json index ab7f6d2aa..7cd660785 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "body-parser": "~1.13.2", "cookie-parser": "~1.3.5", "debug": "~2.2.0", + "ejs": "^2.4.2", "express": "~4.13.1", "jade": "~1.11.0", "massive": "^2.3.0", diff --git a/routes/index.js b/routes/index.js index 3f94b731a..b7aeb91ba 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,5 +1,7 @@ var express = require('express'); var router = express.Router(); +var ApiController = require('../controllers/api') + /* GET home page. */ router.get('/', function(req, res, next) { @@ -10,13 +12,9 @@ router.get('/zomg', function(req, res, next) { res.status(200).json({message: 'it works!'}) }); -router.get('/api/docs', function(req, res, next) { - res.render('docs') -}); +router.get('/api/docs', ApiController.docs); -router.get('/api/docs.json', function(req, res, next) { - res.status(200).json({message: 'docs, yo!'}) -}); +router.get('/api/docs.json', ApiController.jsonDocs); diff --git a/views/docs.ejs b/views/docs.ejs new file mode 100644 index 000000000..8b46d6396 --- /dev/null +++ b/views/docs.ejs @@ -0,0 +1,15 @@ + + + <%= title %> + + + + + + + + <% for (var i in docs) { + <%= i %> + <% } %> + + diff --git a/views/docs.jade b/views/jadedocs.jade similarity index 100% rename from views/docs.jade rename to views/jadedocs.jade From cbfe66f0683700910334c562e81981134ceea98e Mon Sep 17 00:00:00 2001 From: Nadine Curry Date: Fri, 24 Jun 2016 16:26:38 -0700 Subject: [PATCH 101/101] more controller tests --- spec/controllers/customers.spec.js | 32 ++++++++++++++++++++ spec/controllers/movies.spec.js | 10 +++---- spec/controllers/rentals.spec.js | 48 ++++++++++++++++++++++++++++++ spec/models/customer.spec.js | 2 +- 4 files changed, 86 insertions(+), 6 deletions(-) diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js index 7c7624500..df88d9c81 100644 --- a/spec/controllers/customers.spec.js +++ b/spec/controllers/customers.spec.js @@ -59,4 +59,36 @@ describe("CustomersController", function(){ }) }) }) + + describe("#current", function(done){ + it("returns a success response", function(done){ + request.get(base_url+"/1/current", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url+"/1/current", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) + + describe("#history", function(done){ + it("returns a success response", function(done){ + request.get(base_url+"/33/history", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url+"/33/history", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) }) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index a9ba62a8c..049757f3b 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -35,8 +35,8 @@ describe("RentalsController", function(){ }) describe('/movies/sort/', function () { - var goodSort = 'sort/release_date?n=5&p=1' - var badSort = 'sort/year?n=5&p1' + var goodSort = '/sort/release_date?n=5&p=1' + var badSort = '/sort/year?n=5&p1' it('responds with 200 for a good request', function (done) { request.get(base_url + goodSort, function(error, response, body) { @@ -62,8 +62,8 @@ describe("RentalsController", function(){ }) describe('/movies/:title/current', function () { - var goodCurrent = 'Psycho/current' - var badCurrent = 'Young%20Frankenstein/current' + var goodCurrent = '/Psycho/current' + var badCurrent = '/Young%20Frankenstein/current' it('responds with 200 for a good request', function (done) { request.get(base_url + goodCurrent, function(error, response, body) { @@ -81,7 +81,7 @@ describe("RentalsController", function(){ it('responds with empty array for bad request', function (done) { request.get(base_url + badCurrent, function(error, response, body) { - expect(response).toEqual([]) + expect(body).toEqual('[]') done() }) }) diff --git a/spec/controllers/rentals.spec.js b/spec/controllers/rentals.spec.js index 1360824b6..852dc3ba0 100644 --- a/spec/controllers/rentals.spec.js +++ b/spec/controllers/rentals.spec.js @@ -35,4 +35,52 @@ describe("RentalsController", function(){ }) }) }) + + describe("#currentlyCheckedOut", function(done){ + it("returns a success response", function(done){ + request.get(base_url+"/Jaws/customers", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.get(base_url+"/Psycho/customers", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) + + describe("#checkout", function(done){ + it("returns a success response", function(done){ + request.post(base_url+"/Jaws/check-out", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.post(base_url+"/Psycho/check-out", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) + + describe("#return", function(done){ + it("returns a success response", function(done){ + request.put(base_url+"/Jaws/return", function(error, response, body){ + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("returns json", function(done){ + request.put(base_url+"/Psycho/return", function(error, response, body){ + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + }) }) \ No newline at end of file diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js index e0b01597a..4b2c4efb0 100644 --- a/spec/models/customer.spec.js +++ b/spec/models/customer.spec.js @@ -91,7 +91,7 @@ describe('Customer', function () { it('be a certain size', function(done) { Customer.rentedThisMovie(['Psycho', 'name'], function(error,customers){ - expect(customers.length).toEqual(3) + expect(customers.length).toBeGreaterThan(2) done() }) })