diff --git a/app.js b/app.js index f0579b1dc..80e5b00a7 100644 --- a/app.js +++ b/app.js @@ -1,34 +1,47 @@ -var express = require('express'); -var path = require('path'); -var favicon = require('serve-favicon'); -var logger = require('morgan'); -var cookieParser = require('cookie-parser'); -var bodyParser = require('body-parser'); +var express = require('express') +var path = require('path') +var favicon = require('serve-favicon') +var logger = require('morgan') +var cookieParser = require('cookie-parser') +var bodyParser = require('body-parser') -var routes = require('./routes/index'); +var massive = require('massive') +var connectionString = "postgres://localhost/video-store-api" -var app = express(); +var app = module.exports = express() + +var db = massive.connectSync({connectionString : connectionString}) +app.set('db', db) // view engine setup -app.set('views', path.join(__dirname, 'views')); -app.set('view engine', 'jade'); +app.set('views', path.join(__dirname, 'views')) +app.set('view engine', 'jade') + +//views...? +app.engine('html', require('ejs').renderFile) +app.set('view engine', 'html') + +var routes = require('./routes/index') + +var zomgRoutes = require('./routes/zomg') // uncomment after placing your favicon in /public -//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); -app.use(logger('dev')); -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: false })); -app.use(cookieParser()); -app.use(express.static(path.join(__dirname, 'public'))); +//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))) +app.use(logger('dev')) +app.use(bodyParser.json()) +app.use(bodyParser.urlencoded({ extended: false })) +app.use(cookieParser()) +app.use(express.static(path.join(__dirname, 'public'))) -app.use('/', routes); +app.use('/', routes) +app.use('/zomg', zomgRoutes) // catch 404 and forward to error handler app.use(function(req, res, next) { - var err = new Error('Not Found'); - err.status = 404; - next(err); -}); + var err = new Error('Not Found') + err.status = 404 + next(err) +}) // error handlers @@ -36,23 +49,20 @@ app.use(function(req, res, next) { // will print stacktrace if (app.get('env') === 'development') { app.use(function(err, req, res, next) { - res.status(err.status || 500); + res.status(err.status || 500) res.render('error', { message: err.message, error: err - }); - }); + }) + }) } // production error handler // no stacktraces leaked to user app.use(function(err, req, res, next) { - res.status(err.status || 500); + res.status(err.status || 500) res.render('error', { message: err.message, error: {} - }); -}); - - -module.exports = app; + }) +}) diff --git a/controllers/customers_controller.js b/controllers/customers_controller.js new file mode 100644 index 000000000..9f37e43fe --- /dev/null +++ b/controllers/customers_controller.js @@ -0,0 +1,55 @@ +var Customer = require("../models/customer") +var Rental = require("../models/rental") + +var CustomersController = { + + index: function(req, res, next) { + Customer.all(function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + }, + + sort: function(req, res, next) { + Customer.sort(req.params.column_name, req.params.columns, req.query.n, req.query.p, function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + }, + + current: function(req, res, next) { + Rental.current_id(req.params.id, req.params.column_name, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + }, + + history: function(req, res, next) { + Rental.history_cust_id(req.params.id, req.params.column_name, req.params.column, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + } +} + +module.exports = CustomersController diff --git a/controllers/movies_controller.js b/controllers/movies_controller.js new file mode 100644 index 000000000..17ee9fc4c --- /dev/null +++ b/controllers/movies_controller.js @@ -0,0 +1,55 @@ +var Movie = require("../models/movie") +var Rental = require("../models/rental") + +var MoviesController = { + + index: function(req, res, next) { + Movie.all(function(error, movies) { + if(error) { + var err = new Error("Error retrieving movies:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(movies) + } + }) + }, + + sort: function(req, res, next) { + Movie.sort(req.params.column_name, req.query.n, req.query.p, function(error, movies) { + if(error) { + var err = new Error("Error retrieving movies:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(movies) + } + }) + }, + + current: function(req, res, next) { + Rental.current_title(req.params.title, req.params.columns, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + }, + + history: function(req, res, next) { + Rental.history_title(req.params.title, req.params.column_name, function(error, rentals) { + if(error) { + var err = new Error("Error retrieving rentals:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(rentals) + } + }) + } +} + +module.exports = MoviesController diff --git a/controllers/rentals_controller.js b/controllers/rentals_controller.js new file mode 100644 index 000000000..829b9ad8c --- /dev/null +++ b/controllers/rentals_controller.js @@ -0,0 +1,62 @@ +var Rental = require("../models/rental") +var Movie = require("../models/movie") +var Customer = require("../models/customer") + +var RentalsController = { + view: function(req, res, next) { + Rental.view(req.params.title, function(error, movies) { + if(error) { + var err = new Error("Error retrieving movies:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(movies) + } + }) + }, + + customers: function(req, res, next) { + Rental.customers(req.params.title, function(error, customers) { + if(error) { + var err = new Error("Error retrieving customers:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(customers) + } + }) + }, + + check_out: function(req, res) { + var title = req.params.title + var customer_id = req.params.customer_id + + Rental.check_out(title, customer_id, function(error, result, next) { + if(error) { + var err = new Error("Error completing rental:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(result) + res.statusCode = 204 + } + }) + }, + + return_rental: function(req, res) { + console.log("request: " + res) + + Rental.return_rental(title, customer_id, function(error, result, next) { + if(error) { + var err = new Error("Error completing rental:\n" + error.message) + err.status = 500 + next(err) + } else { + res.json(result) + res.statusCode = 204 + } + }) + } +} + +module.exports = RentalsController diff --git a/coverage/coverage.json b/coverage/coverage.json new file mode 100644 index 000000000..5336593d0 --- /dev/null +++ b/coverage/coverage.json @@ -0,0 +1 @@ +{"/Users/sakne/C5/projects/VideoStoreAPI/app.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/app.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":1,"8":1,"9":1,"10":1,"11":1,"12":1,"13":1,"14":1,"15":1,"16":1,"17":1,"18":1,"19":1,"20":1,"21":1,"22":1,"23":1,"24":0,"25":0,"26":0,"27":1,"28":0,"29":0,"30":0,"31":1,"32":0,"33":0},"b":{"1":[0,1],"2":[0,0],"3":[0,0]},"f":{"1":0,"2":0,"3":0},"fnMap":{"1":{"name":"(anonymous_1)","line":36,"loc":{"start":{"line":36,"column":8},"end":{"line":36,"column":33}}},"2":{"name":"(anonymous_2)","line":47,"loc":{"start":{"line":47,"column":10},"end":{"line":47,"column":40}}},"3":{"name":"(anonymous_3)","line":58,"loc":{"start":{"line":58,"column":8},"end":{"line":58,"column":38}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":26}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":38}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":30}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":43}},"6":{"start":{"line":6,"column":0},"end":{"line":6,"column":39}},"7":{"start":{"line":8,"column":0},"end":{"line":8,"column":32}},"8":{"start":{"line":9,"column":0},"end":{"line":9,"column":61}},"9":{"start":{"line":11,"column":0},"end":{"line":11,"column":36}},"10":{"start":{"line":13,"column":0},"end":{"line":13,"column":67}},"11":{"start":{"line":14,"column":0},"end":{"line":14,"column":17}},"12":{"start":{"line":17,"column":0},"end":{"line":17,"column":47}},"13":{"start":{"line":18,"column":0},"end":{"line":18,"column":30}},"14":{"start":{"line":20,"column":0},"end":{"line":20,"column":38}},"15":{"start":{"line":22,"column":0},"end":{"line":22,"column":41}},"16":{"start":{"line":26,"column":0},"end":{"line":26,"column":22}},"17":{"start":{"line":27,"column":0},"end":{"line":27,"column":26}},"18":{"start":{"line":28,"column":0},"end":{"line":28,"column":51}},"19":{"start":{"line":29,"column":0},"end":{"line":29,"column":23}},"20":{"start":{"line":30,"column":0},"end":{"line":30,"column":55}},"21":{"start":{"line":32,"column":0},"end":{"line":32,"column":20}},"22":{"start":{"line":33,"column":0},"end":{"line":33,"column":28}},"23":{"start":{"line":36,"column":0},"end":{"line":40,"column":2}},"24":{"start":{"line":37,"column":2},"end":{"line":37,"column":34}},"25":{"start":{"line":38,"column":2},"end":{"line":38,"column":18}},"26":{"start":{"line":39,"column":2},"end":{"line":39,"column":11}},"27":{"start":{"line":46,"column":0},"end":{"line":54,"column":1}},"28":{"start":{"line":47,"column":2},"end":{"line":53,"column":4}},"29":{"start":{"line":48,"column":4},"end":{"line":48,"column":33}},"30":{"start":{"line":49,"column":4},"end":{"line":52,"column":6}},"31":{"start":{"line":58,"column":0},"end":{"line":64,"column":2}},"32":{"start":{"line":59,"column":2},"end":{"line":59,"column":31}},"33":{"start":{"line":60,"column":2},"end":{"line":63,"column":4}}},"branchMap":{"1":{"line":46,"type":"if","locations":[{"start":{"line":46,"column":0},"end":{"line":46,"column":0}},{"start":{"line":46,"column":0},"end":{"line":46,"column":0}}]},"2":{"line":48,"type":"binary-expr","locations":[{"start":{"line":48,"column":15},"end":{"line":48,"column":25}},{"start":{"line":48,"column":29},"end":{"line":48,"column":32}}]},"3":{"line":59,"type":"binary-expr","locations":[{"start":{"line":59,"column":13},"end":{"line":59,"column":23}},{"start":{"line":59,"column":27},"end":{"line":59,"column":30}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/routes/index.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/routes/index.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":1,"7":0,"8":1,"9":0,"10":1,"11":0,"12":1,"13":0,"14":1,"15":0,"16":1,"17":0,"18":1,"19":0,"20":1,"21":0,"22":1,"23":0,"24":1,"25":0,"26":1,"27":0,"28":1,"29":0,"30":1,"31":0,"32":1,"33":0,"34":1},"b":{},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0},"fnMap":{"1":{"name":"(anonymous_1)","line":7,"loc":{"start":{"line":7,"column":16},"end":{"line":7,"column":41}}},"2":{"name":"(anonymous_2)","line":11,"loc":{"start":{"line":11,"column":22},"end":{"line":11,"column":47}}},"3":{"name":"(anonymous_3)","line":15,"loc":{"start":{"line":15,"column":40},"end":{"line":15,"column":65}}},"4":{"name":"(anonymous_4)","line":20,"loc":{"start":{"line":20,"column":0},"end":{"line":20,"column":25}}},"5":{"name":"(anonymous_5)","line":24,"loc":{"start":{"line":24,"column":54},"end":{"line":24,"column":78}}},"6":{"name":"(anonymous_6)","line":28,"loc":{"start":{"line":28,"column":25},"end":{"line":28,"column":49}}},"7":{"name":"(anonymous_7)","line":32,"loc":{"start":{"line":32,"column":43},"end":{"line":32,"column":68}}},"8":{"name":"(anonymous_8)","line":36,"loc":{"start":{"line":36,"column":37},"end":{"line":36,"column":61}}},"9":{"name":"(anonymous_9)","line":41,"loc":{"start":{"line":41,"column":0},"end":{"line":41,"column":25}}},"10":{"name":"(anonymous_10)","line":47,"loc":{"start":{"line":47,"column":0},"end":{"line":47,"column":25}}},"11":{"name":"(anonymous_11)","line":52,"loc":{"start":{"line":52,"column":0},"end":{"line":52,"column":25}}},"12":{"name":"(anonymous_12)","line":57,"loc":{"start":{"line":57,"column":0},"end":{"line":57,"column":25}}},"13":{"name":"(anonymous_13)","line":62,"loc":{"start":{"line":62,"column":0},"end":{"line":62,"column":25}}},"14":{"name":"(anonymous_14)","line":67,"loc":{"start":{"line":67,"column":0},"end":{"line":67,"column":25}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":29}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":67}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":73}},"5":{"start":{"line":5,"column":0},"end":{"line":5,"column":69}},"6":{"start":{"line":7,"column":0},"end":{"line":9,"column":2}},"7":{"start":{"line":8,"column":2},"end":{"line":8,"column":47}},"8":{"start":{"line":11,"column":0},"end":{"line":13,"column":2}},"9":{"start":{"line":12,"column":2},"end":{"line":12,"column":41}},"10":{"start":{"line":15,"column":0},"end":{"line":17,"column":2}},"11":{"start":{"line":16,"column":2},"end":{"line":16,"column":40}},"12":{"start":{"line":19,"column":0},"end":{"line":22,"column":2}},"13":{"start":{"line":21,"column":2},"end":{"line":21,"column":43}},"14":{"start":{"line":24,"column":0},"end":{"line":26,"column":2}},"15":{"start":{"line":25,"column":2},"end":{"line":25,"column":43}},"16":{"start":{"line":28,"column":0},"end":{"line":30,"column":2}},"17":{"start":{"line":29,"column":2},"end":{"line":29,"column":44}},"18":{"start":{"line":32,"column":0},"end":{"line":34,"column":2}},"19":{"start":{"line":33,"column":2},"end":{"line":33,"column":43}},"20":{"start":{"line":36,"column":0},"end":{"line":38,"column":2}},"21":{"start":{"line":37,"column":2},"end":{"line":37,"column":46}},"22":{"start":{"line":40,"column":0},"end":{"line":43,"column":2}},"23":{"start":{"line":42,"column":2},"end":{"line":42,"column":46}},"24":{"start":{"line":46,"column":0},"end":{"line":49,"column":2}},"25":{"start":{"line":48,"column":2},"end":{"line":48,"column":41}},"26":{"start":{"line":51,"column":0},"end":{"line":54,"column":2}},"27":{"start":{"line":53,"column":2},"end":{"line":53,"column":46}},"28":{"start":{"line":56,"column":0},"end":{"line":59,"column":2}},"29":{"start":{"line":58,"column":2},"end":{"line":58,"column":46}},"30":{"start":{"line":61,"column":0},"end":{"line":64,"column":2}},"31":{"start":{"line":63,"column":2},"end":{"line":63,"column":43}},"32":{"start":{"line":66,"column":0},"end":{"line":69,"column":2}},"33":{"start":{"line":68,"column":2},"end":{"line":68,"column":44}},"34":{"start":{"line":73,"column":0},"end":{"line":73,"column":23}}},"branchMap":{}},"/Users/sakne/C5/projects/VideoStoreAPI/controllers/movies_controller.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/controllers/movies_controller.js","s":{"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":34}}},"2":{"name":"(anonymous_2)","line":7,"loc":{"start":{"line":7,"column":14},"end":{"line":7,"column":38}}},"3":{"name":"(anonymous_3)","line":18,"loc":{"start":{"line":18,"column":8},"end":{"line":18,"column":33}}},"4":{"name":"(anonymous_4)","line":19,"loc":{"start":{"line":19,"column":65},"end":{"line":19,"column":89}}},"5":{"name":"(anonymous_5)","line":30,"loc":{"start":{"line":30,"column":11},"end":{"line":30,"column":36}}},"6":{"name":"(anonymous_6)","line":31,"loc":{"start":{"line":31,"column":63},"end":{"line":31,"column":88}}},"7":{"name":"(anonymous_7)","line":42,"loc":{"start":{"line":42,"column":11},"end":{"line":42,"column":36}}},"8":{"name":"(anonymous_8)","line":43,"loc":{"start":{"line":43,"column":67},"end":{"line":43,"column":92}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":40}},"3":{"start":{"line":4,"column":0},"end":{"line":53,"column":1}},"4":{"start":{"line":7,"column":4},"end":{"line":15,"column":6}},"5":{"start":{"line":8,"column":6},"end":{"line":14,"column":7}},"6":{"start":{"line":9,"column":8},"end":{"line":9,"column":73}},"7":{"start":{"line":10,"column":8},"end":{"line":10,"column":24}},"8":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"9":{"start":{"line":13,"column":8},"end":{"line":13,"column":24}},"10":{"start":{"line":19,"column":4},"end":{"line":27,"column":6}},"11":{"start":{"line":20,"column":6},"end":{"line":26,"column":7}},"12":{"start":{"line":21,"column":8},"end":{"line":21,"column":73}},"13":{"start":{"line":22,"column":8},"end":{"line":22,"column":24}},"14":{"start":{"line":23,"column":8},"end":{"line":23,"column":17}},"15":{"start":{"line":25,"column":8},"end":{"line":25,"column":24}},"16":{"start":{"line":31,"column":4},"end":{"line":39,"column":6}},"17":{"start":{"line":32,"column":6},"end":{"line":38,"column":7}},"18":{"start":{"line":33,"column":8},"end":{"line":33,"column":74}},"19":{"start":{"line":34,"column":8},"end":{"line":34,"column":24}},"20":{"start":{"line":35,"column":8},"end":{"line":35,"column":17}},"21":{"start":{"line":37,"column":8},"end":{"line":37,"column":25}},"22":{"start":{"line":43,"column":4},"end":{"line":51,"column":6}},"23":{"start":{"line":44,"column":6},"end":{"line":50,"column":7}},"24":{"start":{"line":45,"column":8},"end":{"line":45,"column":74}},"25":{"start":{"line":46,"column":8},"end":{"line":46,"column":24}},"26":{"start":{"line":47,"column":8},"end":{"line":47,"column":17}},"27":{"start":{"line":49,"column":8},"end":{"line":49,"column":25}},"28":{"start":{"line":55,"column":0},"end":{"line":55,"column":33}}},"branchMap":{"1":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":6},"end":{"line":8,"column":6}},{"start":{"line":8,"column":6},"end":{"line":8,"column":6}}]},"2":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":6},"end":{"line":20,"column":6}},{"start":{"line":20,"column":6},"end":{"line":20,"column":6}}]},"3":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":6},"end":{"line":32,"column":6}},{"start":{"line":32,"column":6},"end":{"line":32,"column":6}}]},"4":{"line":44,"type":"if","locations":[{"start":{"line":44,"column":6},"end":{"line":44,"column":6}},{"start":{"line":44,"column":6},"end":{"line":44,"column":6}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/models/movie.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/models/movie.js","s":{"1":1,"2":1,"3":1,"4":0,"5":1,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":1,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":12},"end":{"line":4,"column":25}}},"2":{"name":"(anonymous_2)","line":8,"loc":{"start":{"line":8,"column":12},"end":{"line":8,"column":31}}},"3":{"name":"(anonymous_3)","line":9,"loc":{"start":{"line":9,"column":17},"end":{"line":9,"column":41}}},"4":{"name":"(anonymous_4)","line":15,"loc":{"start":{"line":15,"column":32},"end":{"line":15,"column":48}}},"5":{"name":"(anonymous_5)","line":22,"loc":{"start":{"line":22,"column":13},"end":{"line":22,"column":51}}},"6":{"name":"(anonymous_6)","line":29,"loc":{"start":{"line":29,"column":30},"end":{"line":29,"column":54}}},"7":{"name":"(anonymous_7)","line":35,"loc":{"start":{"line":35,"column":32},"end":{"line":35,"column":48}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":22}},"3":{"start":{"line":4,"column":0},"end":{"line":6,"column":1}},"4":{"start":{"line":5,"column":2},"end":{"line":5,"column":14}},"5":{"start":{"line":8,"column":0},"end":{"line":20,"column":1}},"6":{"start":{"line":9,"column":2},"end":{"line":19,"column":4}},"7":{"start":{"line":10,"column":4},"end":{"line":18,"column":5}},"8":{"start":{"line":11,"column":6},"end":{"line":11,"column":74}},"9":{"start":{"line":12,"column":11},"end":{"line":18,"column":5}},"10":{"start":{"line":13,"column":6},"end":{"line":13,"column":64}},"11":{"start":{"line":15,"column":6},"end":{"line":17,"column":9}},"12":{"start":{"line":16,"column":8},"end":{"line":16,"column":31}},"13":{"start":{"line":22,"column":0},"end":{"line":40,"column":1}},"14":{"start":{"line":23,"column":2},"end":{"line":27,"column":3}},"15":{"start":{"line":29,"column":2},"end":{"line":39,"column":4}},"16":{"start":{"line":30,"column":4},"end":{"line":38,"column":5}},"17":{"start":{"line":31,"column":6},"end":{"line":31,"column":74}},"18":{"start":{"line":32,"column":11},"end":{"line":38,"column":5}},"19":{"start":{"line":33,"column":6},"end":{"line":33,"column":64}},"20":{"start":{"line":35,"column":6},"end":{"line":37,"column":9}},"21":{"start":{"line":36,"column":8},"end":{"line":36,"column":31}},"22":{"start":{"line":42,"column":0},"end":{"line":42,"column":22}}},"branchMap":{"1":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":4},"end":{"line":10,"column":4}},{"start":{"line":10,"column":4},"end":{"line":10,"column":4}}]},"2":{"line":11,"type":"binary-expr","locations":[{"start":{"line":11,"column":15},"end":{"line":11,"column":20}},{"start":{"line":11,"column":24},"end":{"line":11,"column":62}}]},"3":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":11},"end":{"line":12,"column":11}},{"start":{"line":12,"column":11},"end":{"line":12,"column":11}}]},"4":{"line":13,"type":"binary-expr","locations":[{"start":{"line":13,"column":15},"end":{"line":13,"column":20}},{"start":{"line":13,"column":24},"end":{"line":13,"column":52}}]},"5":{"line":30,"type":"if","locations":[{"start":{"line":30,"column":4},"end":{"line":30,"column":4}},{"start":{"line":30,"column":4},"end":{"line":30,"column":4}}]},"6":{"line":31,"type":"binary-expr","locations":[{"start":{"line":31,"column":15},"end":{"line":31,"column":20}},{"start":{"line":31,"column":24},"end":{"line":31,"column":62}}]},"7":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":11},"end":{"line":32,"column":11}},{"start":{"line":32,"column":11},"end":{"line":32,"column":11}}]},"8":{"line":33,"type":"binary-expr","locations":[{"start":{"line":33,"column":15},"end":{"line":33,"column":20}},{"start":{"line":33,"column":24},"end":{"line":33,"column":52}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/models/rental.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/models/rental.js","s":{"1":1,"2":1,"3":1,"4":1,"5":1,"6":0,"7":1,"8":0,"9":0,"10":0,"11":0,"12":1,"13":0,"14":0,"15":0,"16":0,"17":0,"18":1,"19":0,"20":0,"21":0,"22":0,"23":0,"24":1,"25":0,"26":0,"27":0,"28":0,"29":0,"30":1,"31":0,"32":0,"33":0,"34":0,"35":0,"36":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":13},"end":{"line":6,"column":26}}},"2":{"name":"(anonymous_2)","line":10,"loc":{"start":{"line":10,"column":14},"end":{"line":10,"column":40}}},"3":{"name":"(anonymous_3)","line":11,"loc":{"start":{"line":11,"column":149},"end":{"line":11,"column":174}}},"4":{"name":"(anonymous_4)","line":22,"loc":{"start":{"line":22,"column":23},"end":{"line":22,"column":58}}},"5":{"name":"(anonymous_5)","line":26,"loc":{"start":{"line":26,"column":165},"end":{"line":26,"column":192}}},"6":{"name":"(anonymous_6)","line":35,"loc":{"start":{"line":35,"column":20},"end":{"line":35,"column":56}}},"7":{"name":"(anonymous_7)","line":39,"loc":{"start":{"line":39,"column":140},"end":{"line":39,"column":164}}},"8":{"name":"(anonymous_8)","line":48,"loc":{"start":{"line":48,"column":23},"end":{"line":48,"column":62}}},"9":{"name":"(anonymous_9)","line":49,"loc":{"start":{"line":49,"column":169},"end":{"line":49,"column":199}}},"10":{"name":"(anonymous_10)","line":59,"loc":{"start":{"line":59,"column":25},"end":{"line":59,"column":70}}},"11":{"name":"(anonymous_11)","line":60,"loc":{"start":{"line":60,"column":97},"end":{"line":60,"column":127}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":44}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":38}},"4":{"start":{"line":4,"column":0},"end":{"line":4,"column":22}},"5":{"start":{"line":6,"column":0},"end":{"line":8,"column":1}},"6":{"start":{"line":7,"column":2},"end":{"line":7,"column":14}},"7":{"start":{"line":10,"column":0},"end":{"line":20,"column":1}},"8":{"start":{"line":11,"column":2},"end":{"line":19,"column":4}},"9":{"start":{"line":14,"column":4},"end":{"line":18,"column":5}},"10":{"start":{"line":15,"column":6},"end":{"line":15,"column":32}},"11":{"start":{"line":17,"column":6},"end":{"line":17,"column":29}},"12":{"start":{"line":22,"column":0},"end":{"line":33,"column":1}},"13":{"start":{"line":23,"column":2},"end":{"line":25,"column":3}},"14":{"start":{"line":26,"column":2},"end":{"line":32,"column":4}},"15":{"start":{"line":27,"column":4},"end":{"line":31,"column":5}},"16":{"start":{"line":28,"column":6},"end":{"line":28,"column":32}},"17":{"start":{"line":30,"column":6},"end":{"line":30,"column":31}},"18":{"start":{"line":35,"column":0},"end":{"line":46,"column":1}},"19":{"start":{"line":36,"column":2},"end":{"line":38,"column":3}},"20":{"start":{"line":39,"column":2},"end":{"line":45,"column":4}},"21":{"start":{"line":40,"column":4},"end":{"line":44,"column":5}},"22":{"start":{"line":41,"column":6},"end":{"line":41,"column":32}},"23":{"start":{"line":43,"column":6},"end":{"line":43,"column":28}},"24":{"start":{"line":48,"column":0},"end":{"line":57,"column":1}},"25":{"start":{"line":49,"column":2},"end":{"line":56,"column":4}},"26":{"start":{"line":50,"column":4},"end":{"line":55,"column":5}},"27":{"start":{"line":51,"column":6},"end":{"line":51,"column":32}},"28":{"start":{"line":53,"column":6},"end":{"line":53,"column":49}},"29":{"start":{"line":54,"column":6},"end":{"line":54,"column":34}},"30":{"start":{"line":59,"column":0},"end":{"line":68,"column":1}},"31":{"start":{"line":60,"column":2},"end":{"line":67,"column":4}},"32":{"start":{"line":61,"column":4},"end":{"line":66,"column":5}},"33":{"start":{"line":62,"column":6},"end":{"line":62,"column":32}},"34":{"start":{"line":64,"column":6},"end":{"line":64,"column":49}},"35":{"start":{"line":65,"column":6},"end":{"line":65,"column":34}},"36":{"start":{"line":70,"column":0},"end":{"line":70,"column":23}}},"branchMap":{"1":{"line":14,"type":"if","locations":[{"start":{"line":14,"column":4},"end":{"line":14,"column":4}},{"start":{"line":14,"column":4},"end":{"line":14,"column":4}}]},"2":{"line":27,"type":"if","locations":[{"start":{"line":27,"column":4},"end":{"line":27,"column":4}},{"start":{"line":27,"column":4},"end":{"line":27,"column":4}}]},"3":{"line":40,"type":"if","locations":[{"start":{"line":40,"column":4},"end":{"line":40,"column":4}},{"start":{"line":40,"column":4},"end":{"line":40,"column":4}}]},"4":{"line":50,"type":"if","locations":[{"start":{"line":50,"column":4},"end":{"line":50,"column":4}},{"start":{"line":50,"column":4},"end":{"line":50,"column":4}}]},"5":{"line":61,"type":"if","locations":[{"start":{"line":61,"column":4},"end":{"line":61,"column":4}},{"start":{"line":61,"column":4},"end":{"line":61,"column":4}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/models/customer.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/models/customer.js","s":{"1":1,"2":1,"3":1,"4":400,"5":1,"6":2,"7":2,"8":0,"9":2,"10":0,"11":2,"12":400,"13":1,"14":1,"15":1,"16":1,"17":1,"18":0,"19":0,"20":0,"21":0,"22":1,"23":0,"24":0,"25":0,"26":1},"b":{"1":[0,2],"2":[0,0],"3":[0,2],"4":[0,0],"5":[1,0],"6":[1,0],"7":[0,0],"8":[0,0]},"f":{"1":400,"2":2,"3":2,"4":400,"5":1,"6":1,"7":0,"8":0,"9":0},"fnMap":{"1":{"name":"(anonymous_1)","line":4,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":28}}},"2":{"name":"(anonymous_2)","line":8,"loc":{"start":{"line":8,"column":15},"end":{"line":8,"column":34}}},"3":{"name":"(anonymous_3)","line":9,"loc":{"start":{"line":9,"column":20},"end":{"line":9,"column":47}}},"4":{"name":"(anonymous_4)","line":15,"loc":{"start":{"line":15,"column":35},"end":{"line":15,"column":54}}},"5":{"name":"(anonymous_5)","line":22,"loc":{"start":{"line":22,"column":16},"end":{"line":22,"column":63}}},"6":{"name":"(anonymous_6)","line":30,"loc":{"start":{"line":30,"column":33},"end":{"line":30,"column":60}}},"7":{"name":"(anonymous_7)","line":36,"loc":{"start":{"line":36,"column":35},"end":{"line":36,"column":54}}},"8":{"name":"(anonymous_8)","line":44,"loc":{"start":{"line":44,"column":19},"end":{"line":44,"column":64}}},"9":{"name":"(anonymous_9)","line":50,"loc":{"start":{"line":50,"column":33},"end":{"line":50,"column":59}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":22}},"3":{"start":{"line":4,"column":0},"end":{"line":6,"column":1}},"4":{"start":{"line":5,"column":2},"end":{"line":5,"column":14}},"5":{"start":{"line":8,"column":0},"end":{"line":20,"column":1}},"6":{"start":{"line":9,"column":2},"end":{"line":19,"column":4}},"7":{"start":{"line":10,"column":4},"end":{"line":18,"column":5}},"8":{"start":{"line":11,"column":6},"end":{"line":11,"column":77}},"9":{"start":{"line":12,"column":11},"end":{"line":18,"column":5}},"10":{"start":{"line":13,"column":6},"end":{"line":13,"column":67}},"11":{"start":{"line":15,"column":6},"end":{"line":17,"column":9}},"12":{"start":{"line":16,"column":8},"end":{"line":16,"column":37}},"13":{"start":{"line":22,"column":0},"end":{"line":42,"column":1}},"14":{"start":{"line":23,"column":2},"end":{"line":28,"column":3}},"15":{"start":{"line":30,"column":2},"end":{"line":41,"column":4}},"16":{"start":{"line":31,"column":4},"end":{"line":40,"column":5}},"17":{"start":{"line":32,"column":6},"end":{"line":32,"column":77}},"18":{"start":{"line":33,"column":11},"end":{"line":40,"column":5}},"19":{"start":{"line":34,"column":6},"end":{"line":34,"column":67}},"20":{"start":{"line":36,"column":6},"end":{"line":39,"column":9}},"21":{"start":{"line":38,"column":8},"end":{"line":38,"column":37}},"22":{"start":{"line":44,"column":0},"end":{"line":62,"column":1}},"23":{"start":{"line":45,"column":2},"end":{"line":48,"column":3}},"24":{"start":{"line":50,"column":2},"end":{"line":61,"column":4}},"25":{"start":{"line":58,"column":8},"end":{"line":58,"column":37}},"26":{"start":{"line":65,"column":0},"end":{"line":65,"column":25}}},"branchMap":{"1":{"line":10,"type":"if","locations":[{"start":{"line":10,"column":4},"end":{"line":10,"column":4}},{"start":{"line":10,"column":4},"end":{"line":10,"column":4}}]},"2":{"line":11,"type":"binary-expr","locations":[{"start":{"line":11,"column":15},"end":{"line":11,"column":20}},{"start":{"line":11,"column":24},"end":{"line":11,"column":65}}]},"3":{"line":12,"type":"if","locations":[{"start":{"line":12,"column":11},"end":{"line":12,"column":11}},{"start":{"line":12,"column":11},"end":{"line":12,"column":11}}]},"4":{"line":13,"type":"binary-expr","locations":[{"start":{"line":13,"column":15},"end":{"line":13,"column":20}},{"start":{"line":13,"column":24},"end":{"line":13,"column":55}}]},"5":{"line":31,"type":"if","locations":[{"start":{"line":31,"column":4},"end":{"line":31,"column":4}},{"start":{"line":31,"column":4},"end":{"line":31,"column":4}}]},"6":{"line":32,"type":"binary-expr","locations":[{"start":{"line":32,"column":15},"end":{"line":32,"column":20}},{"start":{"line":32,"column":24},"end":{"line":32,"column":65}}]},"7":{"line":33,"type":"if","locations":[{"start":{"line":33,"column":11},"end":{"line":33,"column":11}},{"start":{"line":33,"column":11},"end":{"line":33,"column":11}}]},"8":{"line":34,"type":"binary-expr","locations":[{"start":{"line":34,"column":15},"end":{"line":34,"column":20}},{"start":{"line":34,"column":24},"end":{"line":34,"column":55}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/controllers/customers_controller.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/controllers/customers_controller.js","s":{"1":1,"2":1,"3":1,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":1},"b":{"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0]},"f":{"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":34}}},"2":{"name":"(anonymous_2)","line":7,"loc":{"start":{"line":7,"column":17},"end":{"line":7,"column":44}}},"3":{"name":"(anonymous_3)","line":18,"loc":{"start":{"line":18,"column":8},"end":{"line":18,"column":33}}},"4":{"name":"(anonymous_4)","line":19,"loc":{"start":{"line":19,"column":88},"end":{"line":19,"column":115}}},"5":{"name":"(anonymous_5)","line":30,"loc":{"start":{"line":30,"column":11},"end":{"line":30,"column":36}}},"6":{"name":"(anonymous_6)","line":31,"loc":{"start":{"line":31,"column":61},"end":{"line":31,"column":86}}},"7":{"name":"(anonymous_7)","line":42,"loc":{"start":{"line":42,"column":11},"end":{"line":42,"column":36}}},"8":{"name":"(anonymous_8)","line":43,"loc":{"start":{"line":43,"column":85},"end":{"line":43,"column":110}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":40}},"3":{"start":{"line":4,"column":0},"end":{"line":53,"column":1}},"4":{"start":{"line":7,"column":4},"end":{"line":15,"column":6}},"5":{"start":{"line":8,"column":6},"end":{"line":14,"column":7}},"6":{"start":{"line":9,"column":8},"end":{"line":9,"column":76}},"7":{"start":{"line":10,"column":8},"end":{"line":10,"column":24}},"8":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"9":{"start":{"line":13,"column":8},"end":{"line":13,"column":27}},"10":{"start":{"line":19,"column":4},"end":{"line":27,"column":6}},"11":{"start":{"line":20,"column":6},"end":{"line":26,"column":7}},"12":{"start":{"line":21,"column":8},"end":{"line":21,"column":76}},"13":{"start":{"line":22,"column":8},"end":{"line":22,"column":24}},"14":{"start":{"line":23,"column":8},"end":{"line":23,"column":17}},"15":{"start":{"line":25,"column":8},"end":{"line":25,"column":27}},"16":{"start":{"line":31,"column":4},"end":{"line":39,"column":6}},"17":{"start":{"line":32,"column":6},"end":{"line":38,"column":7}},"18":{"start":{"line":33,"column":8},"end":{"line":33,"column":71}},"19":{"start":{"line":34,"column":8},"end":{"line":34,"column":24}},"20":{"start":{"line":35,"column":8},"end":{"line":35,"column":17}},"21":{"start":{"line":37,"column":8},"end":{"line":37,"column":25}},"22":{"start":{"line":43,"column":4},"end":{"line":51,"column":6}},"23":{"start":{"line":44,"column":6},"end":{"line":50,"column":7}},"24":{"start":{"line":45,"column":8},"end":{"line":45,"column":74}},"25":{"start":{"line":46,"column":8},"end":{"line":46,"column":24}},"26":{"start":{"line":47,"column":8},"end":{"line":47,"column":17}},"27":{"start":{"line":49,"column":8},"end":{"line":49,"column":25}},"28":{"start":{"line":55,"column":0},"end":{"line":55,"column":36}}},"branchMap":{"1":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":6},"end":{"line":8,"column":6}},{"start":{"line":8,"column":6},"end":{"line":8,"column":6}}]},"2":{"line":20,"type":"if","locations":[{"start":{"line":20,"column":6},"end":{"line":20,"column":6}},{"start":{"line":20,"column":6},"end":{"line":20,"column":6}}]},"3":{"line":32,"type":"if","locations":[{"start":{"line":32,"column":6},"end":{"line":32,"column":6}},{"start":{"line":32,"column":6},"end":{"line":32,"column":6}}]},"4":{"line":44,"type":"if","locations":[{"start":{"line":44,"column":6},"end":{"line":44,"column":6}},{"start":{"line":44,"column":6},"end":{"line":44,"column":6}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/controllers/rentals_controller.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/controllers/rentals_controller.js","s":{"1":1,"2":1,"3":1,"4":1,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":1},"b":{"1":[0,0]},"f":{"1":0,"2":0},"fnMap":{"1":{"name":"(anonymous_1)","line":6,"loc":{"start":{"line":6,"column":8},"end":{"line":6,"column":33}}},"2":{"name":"(anonymous_2)","line":7,"loc":{"start":{"line":7,"column":34},"end":{"line":7,"column":58}}}},"statementMap":{"1":{"start":{"line":1,"column":0},"end":{"line":1,"column":40}},"2":{"start":{"line":2,"column":0},"end":{"line":2,"column":38}},"3":{"start":{"line":3,"column":0},"end":{"line":3,"column":44}},"4":{"start":{"line":5,"column":0},"end":{"line":40,"column":1}},"5":{"start":{"line":7,"column":4},"end":{"line":16,"column":6}},"6":{"start":{"line":8,"column":6},"end":{"line":15,"column":7}},"7":{"start":{"line":9,"column":8},"end":{"line":9,"column":73}},"8":{"start":{"line":10,"column":8},"end":{"line":10,"column":24}},"9":{"start":{"line":11,"column":8},"end":{"line":11,"column":17}},"10":{"start":{"line":14,"column":8},"end":{"line":14,"column":24}},"11":{"start":{"line":42,"column":0},"end":{"line":42,"column":34}}},"branchMap":{"1":{"line":8,"type":"if","locations":[{"start":{"line":8,"column":6},"end":{"line":8,"column":6}},{"start":{"line":8,"column":6},"end":{"line":8,"column":6}}]}}},"/Users/sakne/C5/projects/VideoStoreAPI/routes/zomg.js":{"path":"/Users/sakne/C5/projects/VideoStoreAPI/routes/zomg.js","s":{"1":1,"2":1,"3":1,"4":1,"5":0,"6":1},"b":{},"f":{"1":0},"fnMap":{"1":{"name":"(anonymous_1)","line":30,"loc":{"start":{"line":30,"column":16},"end":{"line":30,"column":41}}}},"statementMap":{"1":{"start":{"line":25,"column":0},"end":{"line":25,"column":33}},"2":{"start":{"line":26,"column":0},"end":{"line":26,"column":30}},"3":{"start":{"line":27,"column":0},"end":{"line":27,"column":15}},"4":{"start":{"line":30,"column":0},"end":{"line":32,"column":3}},"5":{"start":{"line":31,"column":2},"end":{"line":31,"column":44}},"6":{"start":{"line":34,"column":0},"end":{"line":34,"column":24}}},"branchMap":{}}} \ No newline at end of file diff --git a/coverage/lcov-report/VideoStoreAPI/app.js.html b/coverage/lcov-report/VideoStoreAPI/app.js.html new file mode 100644 index 000000000..801410501 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/app.js.html @@ -0,0 +1,257 @@ + + + + Code coverage report for VideoStoreAPI/app.js + + + + + + + +
+
+

+ all files / VideoStoreAPI/ app.js +

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

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

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

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

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

+ all files VideoStoreAPI/controllers/ +

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

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

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

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

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

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

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

+ all files VideoStoreAPI/ +

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

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

+
+
+ 65.38% + Statements + 17/26 +
+
+ 25% + Branches + 4/16 +
+
+ 66.67% + Functions + 6/9 +
+
+ 65.38% + Lines + 17/26 +
+
+
+
+

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

+ all files VideoStoreAPI/models/ +

+
+
+ 40.48% + Statements + 34/84 +
+
+ 9.52% + Branches + 4/42 +
+
+ 22.22% + Functions + 6/27 +
+
+ 40.48% + Lines + 34/84 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
customer.js
65.38%17/2625%4/1666.67%6/965.38%17/26
movie.js
27.27%6/220%0/160%0/727.27%6/22
rental.js
30.56%11/360%0/100%0/1130.56%11/36
+
+
+ + + + + + + diff --git a/coverage/lcov-report/VideoStoreAPI/models/movie.js.html b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html new file mode 100644 index 000000000..66a910e92 --- /dev/null +++ b/coverage/lcov-report/VideoStoreAPI/models/movie.js.html @@ -0,0 +1,191 @@ + + + + Code coverage report for VideoStoreAPI/models/movie.js + + + + + + + +
+
+

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

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

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

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

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

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

+ all files VideoStoreAPI/routes/ +

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

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

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

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

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

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

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

+ / +

+
+
+ 43.3% + Statements + 97/224 +
+
+ 7.58% + Branches + 5/66 +
+
+ 9.52% + Functions + 6/63 +
+
+ 43.3% + Lines + 97/224 +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
VideoStoreAPI/
75.76%25/3316.67%1/60%0/375.76%25/33
VideoStoreAPI/controllers/
19.4%13/670%0/180%0/1819.4%13/67
VideoStoreAPI/models/
40.48%34/849.52%4/4222.22%6/2740.48%34/84
VideoStoreAPI/routes/
62.5%25/40100%0/00%0/1562.5%25/40
+
+
+ + + + + + + diff --git a/coverage/lcov-report/prettify.css b/coverage/lcov-report/prettify.css new file mode 100644 index 000000000..b317a7cda --- /dev/null +++ b/coverage/lcov-report/prettify.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/coverage/lcov-report/prettify.js b/coverage/lcov-report/prettify.js new file mode 100644 index 000000000..ef51e0386 --- /dev/null +++ b/coverage/lcov-report/prettify.js @@ -0,0 +1 @@ +window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/coverage/lcov-report/sort-arrow-sprite.png b/coverage/lcov-report/sort-arrow-sprite.png new file mode 100644 index 000000000..03f704a60 Binary files /dev/null and b/coverage/lcov-report/sort-arrow-sprite.png differ diff --git a/coverage/lcov-report/sorter.js b/coverage/lcov-report/sorter.js new file mode 100644 index 000000000..6c5034e40 --- /dev/null +++ b/coverage/lcov-report/sorter.js @@ -0,0 +1,158 @@ +var addSorting = (function () { + "use strict"; + var cols, + currentSort = { + index: 0, + desc: false + }; + + // returns the summary table element + function getTable() { return document.querySelector('.coverage-summary'); } + // returns the thead element of the summary table + function getTableHeader() { return getTable().querySelector('thead tr'); } + // returns the tbody element of the summary table + function getTableBody() { return getTable().querySelector('tbody'); } + // returns the th element for nth column + function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; } + + // loads all columns + function loadColumns() { + var colNodes = getTableHeader().querySelectorAll('th'), + colNode, + cols = [], + col, + i; + + for (i = 0; i < colNodes.length; i += 1) { + colNode = colNodes[i]; + col = { + key: colNode.getAttribute('data-col'), + sortable: !colNode.getAttribute('data-nosort'), + type: colNode.getAttribute('data-type') || 'string' + }; + cols.push(col); + if (col.sortable) { + col.defaultDescSort = col.type === 'number'; + colNode.innerHTML = colNode.innerHTML + ''; + } + } + return cols; + } + // attaches a data attribute to every tr element with an object + // of data values keyed by column name + function loadRowData(tableRow) { + var tableCols = tableRow.querySelectorAll('td'), + colNode, + col, + data = {}, + i, + val; + for (i = 0; i < tableCols.length; i += 1) { + colNode = tableCols[i]; + col = cols[i]; + val = colNode.getAttribute('data-value'); + if (col.type === 'number') { + val = Number(val); + } + data[col.key] = val; + } + return data; + } + // loads all row data + function loadData() { + var rows = getTableBody().querySelectorAll('tr'), + i; + + for (i = 0; i < rows.length; i += 1) { + rows[i].data = loadRowData(rows[i]); + } + } + // sorts the table using the data for the ith column + function sortByIndex(index, desc) { + var key = cols[index].key, + sorter = function (a, b) { + a = a.data[key]; + b = b.data[key]; + return a < b ? -1 : a > b ? 1 : 0; + }, + finalSorter = sorter, + tableBody = document.querySelector('.coverage-summary tbody'), + rowNodes = tableBody.querySelectorAll('tr'), + rows = [], + i; + + if (desc) { + finalSorter = function (a, b) { + return -1 * sorter(a, b); + }; + } + + for (i = 0; i < rowNodes.length; i += 1) { + rows.push(rowNodes[i]); + tableBody.removeChild(rowNodes[i]); + } + + rows.sort(finalSorter); + + for (i = 0; i < rows.length; i += 1) { + tableBody.appendChild(rows[i]); + } + } + // removes sort indicators for current column being sorted + function removeSortIndicators() { + var col = getNthColumn(currentSort.index), + cls = col.className; + + cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); + col.className = cls; + } + // adds sort indicators for current column being sorted + function addSortIndicators() { + getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; + } + // adds event listeners for all sorter widgets + function enableUI() { + var i, + el, + ithSorter = function ithSorter(i) { + var col = cols[i]; + + return function () { + var desc = col.defaultDescSort; + + if (currentSort.index === i) { + desc = !currentSort.desc; + } + sortByIndex(i, desc); + removeSortIndicators(); + currentSort.index = i; + currentSort.desc = desc; + addSortIndicators(); + }; + }; + for (i =0 ; i < cols.length; i += 1) { + if (cols[i].sortable) { + // add the click event handler on the th so users + // dont have to click on those tiny arrows + el = getNthColumn(i).querySelector('.sorter').parentElement; + if (el.addEventListener) { + el.addEventListener('click', ithSorter(i)); + } else { + el.attachEvent('onclick', ithSorter(i)); + } + } + } + } + // adds sorting functionality to the UI + return function () { + if (!getTable()) { + return; + } + cols = loadColumns(); + loadData(cols); + addSortIndicators(); + enableUI(); + }; +})(); + +window.addEventListener('load', addSorting); diff --git a/coverage/lcov.info b/coverage/lcov.info new file mode 100644 index 000000000..b9ed8f125 --- /dev/null +++ b/coverage/lcov.info @@ -0,0 +1,497 @@ +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/app.js +FN:36,(anonymous_1) +FN:47,(anonymous_2) +FN:58,(anonymous_3) +FNF:3 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:8,1 +DA:9,1 +DA:11,1 +DA:13,1 +DA:14,1 +DA:17,1 +DA:18,1 +DA:20,1 +DA:22,1 +DA:26,1 +DA:27,1 +DA:28,1 +DA:29,1 +DA:30,1 +DA:32,1 +DA:33,1 +DA:36,1 +DA:37,0 +DA:38,0 +DA:39,0 +DA:46,1 +DA:47,0 +DA:48,0 +DA:49,0 +DA:58,1 +DA:59,0 +DA:60,0 +LF:33 +LH:25 +BRDA:46,1,0,0 +BRDA:46,1,1,1 +BRDA:48,2,0,0 +BRDA:48,2,1,0 +BRDA:59,3,0,0 +BRDA:59,3,1,0 +BRF:6 +BRH:1 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/routes/index.js +FN:7,(anonymous_1) +FN:11,(anonymous_2) +FN:15,(anonymous_3) +FN:20,(anonymous_4) +FN:24,(anonymous_5) +FN:28,(anonymous_6) +FN:32,(anonymous_7) +FN:36,(anonymous_8) +FN:41,(anonymous_9) +FN:47,(anonymous_10) +FN:52,(anonymous_11) +FN:57,(anonymous_12) +FN:62,(anonymous_13) +FN:67,(anonymous_14) +FNF:14 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +FNDA:0,(anonymous_12) +FNDA:0,(anonymous_13) +FNDA:0,(anonymous_14) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:7,1 +DA:8,0 +DA:11,1 +DA:12,0 +DA:15,1 +DA:16,0 +DA:19,1 +DA:21,0 +DA:24,1 +DA:25,0 +DA:28,1 +DA:29,0 +DA:32,1 +DA:33,0 +DA:36,1 +DA:37,0 +DA:40,1 +DA:42,0 +DA:46,1 +DA:48,0 +DA:51,1 +DA:53,0 +DA:56,1 +DA:58,0 +DA:61,1 +DA:63,0 +DA:66,1 +DA:68,0 +DA:73,1 +LF:34 +LH:20 +BRF:0 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/controllers/movies_controller.js +FN:6,(anonymous_1) +FN:7,(anonymous_2) +FN:18,(anonymous_3) +FN:19,(anonymous_4) +FN:30,(anonymous_5) +FN:31,(anonymous_6) +FN:42,(anonymous_7) +FN:43,(anonymous_8) +FNF:8 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +DA:1,1 +DA:2,1 +DA:4,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:13,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:37,0 +DA:43,0 +DA:44,0 +DA:45,0 +DA:46,0 +DA:47,0 +DA:49,0 +DA:55,1 +LF:28 +LH:4 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRDA:20,2,0,0 +BRDA:20,2,1,0 +BRDA:32,3,0,0 +BRDA:32,3,1,0 +BRDA:44,4,0,0 +BRDA:44,4,1,0 +BRF:8 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/models/movie.js +FN:4,(anonymous_1) +FN:8,(anonymous_2) +FN:9,(anonymous_3) +FN:15,(anonymous_4) +FN:22,(anonymous_5) +FN:29,(anonymous_6) +FN:35,(anonymous_7) +FNF:7 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +DA:1,1 +DA:2,1 +DA:4,1 +DA:5,0 +DA:8,1 +DA:9,0 +DA:10,0 +DA:11,0 +DA:12,0 +DA:13,0 +DA:15,0 +DA:16,0 +DA:22,1 +DA:23,0 +DA:29,0 +DA:30,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:35,0 +DA:36,0 +DA:42,1 +LF:22 +LH:6 +BRDA:10,1,0,0 +BRDA:10,1,1,0 +BRDA:11,2,0,0 +BRDA:11,2,1,0 +BRDA:12,3,0,0 +BRDA:12,3,1,0 +BRDA:13,4,0,0 +BRDA:13,4,1,0 +BRDA:30,5,0,0 +BRDA:30,5,1,0 +BRDA:31,6,0,0 +BRDA:31,6,1,0 +BRDA:32,7,0,0 +BRDA:32,7,1,0 +BRDA:33,8,0,0 +BRDA:33,8,1,0 +BRF:16 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/models/rental.js +FN:6,(anonymous_1) +FN:10,(anonymous_2) +FN:11,(anonymous_3) +FN:22,(anonymous_4) +FN:26,(anonymous_5) +FN:35,(anonymous_6) +FN:39,(anonymous_7) +FN:48,(anonymous_8) +FN:49,(anonymous_9) +FN:59,(anonymous_10) +FN:60,(anonymous_11) +FNF:11 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:0,(anonymous_11) +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:6,1 +DA:7,0 +DA:10,1 +DA:11,0 +DA:14,0 +DA:15,0 +DA:17,0 +DA:22,1 +DA:23,0 +DA:26,0 +DA:27,0 +DA:28,0 +DA:30,0 +DA:35,1 +DA:36,0 +DA:39,0 +DA:40,0 +DA:41,0 +DA:43,0 +DA:48,1 +DA:49,0 +DA:50,0 +DA:51,0 +DA:53,0 +DA:54,0 +DA:59,1 +DA:60,0 +DA:61,0 +DA:62,0 +DA:64,0 +DA:65,0 +DA:70,1 +LF:36 +LH:11 +BRDA:14,1,0,0 +BRDA:14,1,1,0 +BRDA:27,2,0,0 +BRDA:27,2,1,0 +BRDA:40,3,0,0 +BRDA:40,3,1,0 +BRDA:50,4,0,0 +BRDA:50,4,1,0 +BRDA:61,5,0,0 +BRDA:61,5,1,0 +BRF:10 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/models/customer.js +FN:4,(anonymous_1) +FN:8,(anonymous_2) +FN:9,(anonymous_3) +FN:15,(anonymous_4) +FN:22,(anonymous_5) +FN:30,(anonymous_6) +FN:36,(anonymous_7) +FN:44,(anonymous_8) +FN:50,(anonymous_9) +FNF:9 +FNH:6 +FNDA:400,(anonymous_1) +FNDA:2,(anonymous_2) +FNDA:2,(anonymous_3) +FNDA:400,(anonymous_4) +FNDA:1,(anonymous_5) +FNDA:1,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +FNDA:0,(anonymous_9) +DA:1,1 +DA:2,1 +DA:4,1 +DA:5,400 +DA:8,1 +DA:9,2 +DA:10,2 +DA:11,0 +DA:12,2 +DA:13,0 +DA:15,2 +DA:16,400 +DA:22,1 +DA:23,1 +DA:30,1 +DA:31,1 +DA:32,1 +DA:33,0 +DA:34,0 +DA:36,0 +DA:38,0 +DA:44,1 +DA:45,0 +DA:50,0 +DA:58,0 +DA:65,1 +LF:26 +LH:17 +BRDA:10,1,0,0 +BRDA:10,1,1,2 +BRDA:11,2,0,0 +BRDA:11,2,1,0 +BRDA:12,3,0,0 +BRDA:12,3,1,2 +BRDA:13,4,0,0 +BRDA:13,4,1,0 +BRDA:31,5,0,1 +BRDA:31,5,1,0 +BRDA:32,6,0,1 +BRDA:32,6,1,0 +BRDA:33,7,0,0 +BRDA:33,7,1,0 +BRDA:34,8,0,0 +BRDA:34,8,1,0 +BRF:16 +BRH:4 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/controllers/customers_controller.js +FN:6,(anonymous_1) +FN:7,(anonymous_2) +FN:18,(anonymous_3) +FN:19,(anonymous_4) +FN:30,(anonymous_5) +FN:31,(anonymous_6) +FN:42,(anonymous_7) +FN:43,(anonymous_8) +FNF:8 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:0,(anonymous_4) +FNDA:0,(anonymous_5) +FNDA:0,(anonymous_6) +FNDA:0,(anonymous_7) +FNDA:0,(anonymous_8) +DA:1,1 +DA:2,1 +DA:4,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:13,0 +DA:19,0 +DA:20,0 +DA:21,0 +DA:22,0 +DA:23,0 +DA:25,0 +DA:31,0 +DA:32,0 +DA:33,0 +DA:34,0 +DA:35,0 +DA:37,0 +DA:43,0 +DA:44,0 +DA:45,0 +DA:46,0 +DA:47,0 +DA:49,0 +DA:55,1 +LF:28 +LH:4 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRDA:20,2,0,0 +BRDA:20,2,1,0 +BRDA:32,3,0,0 +BRDA:32,3,1,0 +BRDA:44,4,0,0 +BRDA:44,4,1,0 +BRF:8 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/controllers/rentals_controller.js +FN:6,(anonymous_1) +FN:7,(anonymous_2) +FNF:2 +FNH:0 +FNDA:0,(anonymous_1) +FNDA:0,(anonymous_2) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:7,0 +DA:8,0 +DA:9,0 +DA:10,0 +DA:11,0 +DA:14,0 +DA:42,1 +LF:11 +LH:5 +BRDA:8,1,0,0 +BRDA:8,1,1,0 +BRF:2 +BRH:0 +end_of_record +TN: +SF:/Users/sakne/C5/projects/VideoStoreAPI/routes/zomg.js +FN:30,(anonymous_1) +FNF:1 +FNH:0 +FNDA:0,(anonymous_1) +DA:25,1 +DA:26,1 +DA:27,1 +DA:30,1 +DA:31,0 +DA:34,1 +LF:6 +LH:5 +BRF:0 +BRH:0 +end_of_record diff --git a/db/rental.sql b/db/rental.sql new file mode 100644 index 000000000..07102b85f --- /dev/null +++ b/db/rental.sql @@ -0,0 +1,14 @@ +-- select title, movie id, where customer_id = params.id +-- make sql file in db +-- queries in that file create js-accessible functions- use them in the model. + +-- SELECT movie_id, title +-- FROM rentals +-- WHERE customer_id=(SELECT id FROM movies WHERE customer_id=$1) AND returned=false", [movie_title] +-- +-- List the movies they currently have checked out (/customers/5/current) +-- List the movies a customer has checked out in the past (/customers/5/history) +-- ordered by check out date +-- includes return date + +db.run("SELECT * FROM rentals;") diff --git a/db/seeds/rentals.json b/db/seeds/rentals.json new file mode 100644 index 000000000..47570978c --- /dev/null +++ b/db/seeds/rentals.json @@ -0,0 +1,82 @@ +[ +{ +"movie_id": "1", +"customer_id": "3", +"title": "Psycho", +"checkout_date": "2012-06-18", +"due_date": "2012-06-16", +"returned_date": "2012-06-16" +}, +{ +"movie_id": "3", +"customer_id": "12", +"title": "The Exorcist", +"checkout_date": "2016-06-14", +"due_date": "2016-06-16", +"returned_date": null +}, +{ +"movie_id": "1", +"customer_id": "9", +"title": "Psycho", +"checkout_date": "2016-04-16", +"due_date": "2016-04-18", +"returned_date": "2016-04-16" +}, +{ +"movie_id": "9", +"customer_id": "28", +"title": "Rosemary's Baby", +"checkout_date": "2011-04-14", +"due_date": "2011-04-16", +"returned_date": null +}, +{ +"movie_id": "1", +"customer_id": "36", +"title": "Psycho", +"checkout_date": "2015-12-08", +"due_date": "2015-12-10", +"returned_date": "2015-12-12" +}, +{ +"movie_id": "14", +"customer_id": "36", +"title": "Rear Window", +"checkout_date": "2015-11-10", +"due_date": "2015-11-12", +"returned_date": null +}, +{ +"movie_id": "15", +"customer_id": "22", +"title": "Deliverance", +"checkout_date": "2014-02-09", +"due_date": "2014-02-11", +"returned_date": null +}, +{ +"movie_id": "18", +"customer_id": "22", +"title": "Vertigo", +"checkout_date": "2015-09-28", +"due_date": "2015-09-30", +"returned_date": "2015-10-01" +}, +{ +"movie_id": "20", +"customer_id": "45", +"title": "High Noon", +"checkout_date": "2016-03-02", +"due_date": "2016-03-04", +"returned_date": "2016-03-04" +}, +{ +"movie_id": "25", +"customer_id": "47", +"title": "Titanic", +"checkout_date": "2016-2-14", +"due_date": "2016-2-16", +"returned_date": "2016-2-20" +} +] diff --git a/db/setup/schema.sql b/db/setup/schema.sql new file mode 100644 index 000000000..ef4a05ec7 --- /dev/null +++ b/db/setup/schema.sql @@ -0,0 +1,32 @@ +DROP TABLE IF EXISTS movies; +CREATE TABLE movies( + id serial PRIMARY KEY, + title text, + overview text, + release_date text, + inventory text +); + +DROP TABLE IF EXISTS customers; +CREATE TABLE customers( + id serial PRIMARY KEY, + name text, + registered_at text, + address text, + city text, + state text, + postal_code text, + phone text, + account_credit float +); + +DROP TABLE IF EXISTS rentals; +CREATE TABLE rentals( + id serial PRIMARY KEY, + movie_id text, + customer_id text, + title text, + checkout_date text, + due_date text, + returned_date text +); diff --git a/db/setup/seed.sql b/db/setup/seed.sql new file mode 100644 index 000000000..e69de29bb diff --git a/models/customer.js b/models/customer.js new file mode 100644 index 000000000..b9a4ccf7c --- /dev/null +++ b/models/customer.js @@ -0,0 +1,59 @@ +var app = require("../app") +var db = app.get('db') + +var Customer = function(id) { + this.id = id +} + +Customer.all = function(callback) { + db.customers.find(function(error, customers) { + if(error) { + callback(error || new Error("Could not retrieve customers"), undefined) + } else if(!customers) { + callback(error || new Error("No customers found"), undefined) + } else { + callback(null, customers.map(function(customer) { + return new Customer(customer) + })) + } + }) +} + +Customer.sort = function(column_name, columns, n, p, callback) { + var options = { + limit : n, + offset : p, + columns : ["name", "registered_at", "postal_code"], + order : column_name + } + + db.customers.find({}, options, function(error, customers) { + if(error) { + callback(error || new Error("Could not retrieve customers"), undefined) + } else if(!customers) { + callback(error || new Error("No customers found"), undefined) + } else { + callback(null, customers.map(function(customer) { + // console.log(customer) + return new Customer(customer) + })) + } + }) +} + +Customer.find_id = function(customer_ids, column_name, columns) { + var options = { + order : column_name, + columns : ['name', 'phone', 'account_credit'] + } + + db.customers.find({}, options, function(error, customer) { + if(error) { + callback(error, undefined) + } else { + callback(null, customer) + } + }) +} + +module.exports = Customer diff --git a/models/movie.js b/models/movie.js new file mode 100644 index 000000000..989e02b11 --- /dev/null +++ b/models/movie.js @@ -0,0 +1,42 @@ +var app = require("../app") +var db = app.get('db') + +var Movie = function(id) { + this.id = id +} + +Movie.all = function(callback) { + db.movies.find(function(error, movies) { + if(error) { + callback(error || new Error("Could not retrieve movies"), undefined) + } else if(!movies) { + callback(error || new Error("No movies found"), undefined) + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie) + })) + } + }) +} + +Movie.sort = function(column_name, n, p, callback) { + var options = { + order : column_name, + limit : n, + offset : p + } + + db.movies.find({}, options, function(error, movies) { + if(error) { + callback(error || new Error("Could not retrieve movies"), undefined) + } else if(!movies) { + callback(error || new Error("No movies found"), undefined) + } else { + callback(null, movies.map(function(movie) { + return new Movie(movie) + })) + } + }) +} + +module.exports = Movie diff --git a/models/rental.js b/models/rental.js new file mode 100644 index 000000000..6ce3152c3 --- /dev/null +++ b/models/rental.js @@ -0,0 +1,136 @@ +var app = require("../app") +var Customer = require("../models/customer") +var Movie = require("../models/movie") +var db = app.get('db') +// Constructor function +var Rental = function(id) { + this.id = id +} + +Rental.view = function(title, callback) { + db.run("SELECT overview, release_date FROM movies WHERE title IN (SELECT title FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, rentals) { + // console.log("rentals: " + JSON.stringify(rentals)) + // console.log("error: " + error) + if(error) { + callback(error, undefined) + } else { + callback(null, rentals) + } + }) +} + +Rental.customers = function(title, callback) { + db.run("SELECT name FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers) { + if(error) { + callback(error, undefined) + } else { + callback(null, customers) + } + }) +} + +Rental.check_out = function(title, customer_id, callback) { + Rental.get_movie_id(title, customer_id, callback) +} + +Rental.get_movie_id = function (title, customer_id, callback) { + db.run("SELECT movie_id FROM rentals WHERE title = $1 LIMIT 1", [title], function(error, res) + { + if (error) { + callback(error, undefined) + } else { + movie_id = res[0]["movie_id"] + Rental.new_rental(movie_id, customer_id, title, callback) + Rental.charge_customer(movie_id, customer_id, title, callback) + } + }) +} + +Rental.new_rental = function (movie_id, customer_id, title, callback) { + var today = new Date() + var today_plus_two = new Date(today) + today_plus_two.setDate(today_plus_two.getDate() + 2) + + db.rentals.save({ + movie_id: movie_id, + customer_id: customer_id, + title: title, + checkout_date: today, + due_date: today_plus_two, + returned_date: null + }, + function (error, rental) { + if (error) { callback(error, undefined) } + }) +} + +Rental.charge_customer = function (movie_id, customer_id, title, callback) { + db.run("UPDATE customers SET account_credit = account_credit-4 WHERE id=$1", [customer_id], function (error, charged) { + if (error) { + callback(error, undefined) + } else { + callback(null, charged) + } + }) +} + +Rental.return_rental = function (title, customer_id, callback) { + var today = new Date() + db.run("UPDATE rentals SET returned_date = $1 WHERE customer_id::int = $2", [today, customer_id], function(error, result) { + if (error) { + callback(error, undefined) + } else { + callback(null, result) + } + }) +} + +Rental.current_title = function(title, columns, callback) { + var options = { + columns : ['name', 'phone', 'account_credit'] + } + db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS null)", [title], function(error, customers) { + if(error) { + callback(error, undefined) + } else { + callback(null, customers) + } + }) +} + +Rental.current_id = function(id, column_name, callback) { + var options = { + order : column_name + } + db.run("SELECT title FROM movies WHERE title IN (SELECT title FROM rentals WHERE customer_id::int = $1 AND returned_date IS null)", [id], function(error, movies) { + if(error) { + callback(error, undefined) + } else { + callback(null, movies) + } + }) +} + +Rental.history_title = function(title, column_name, callback) { + db.run("SELECT name, phone, account_credit FROM customers WHERE id IN (SELECT customer_id::int FROM rentals WHERE title = $1 AND returned_date IS NOT null)", [title], function(error, customer_ids) { + if(error) { + callback(error, undefined) + } else { + Customer.find_id(customer_ids, column_name) + callback(null, customer_ids) + } + }) +} + +Rental.history_cust_id = function(id, column_name, columns, callback) { + db.run("SELECT title FROM rentals WHERE customer_id = $1 AND returned_date IS NOT null", [id], function(error, customer_ids) { + if(error) { + callback(error, undefined) + } else { + Customer.find_id(customer_ids, column_name) + callback(null, customer_ids) + } + }) +} + +module.exports = Rental diff --git a/package.json b/package.json index d39b26403..8719e6170 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,24 @@ "private": true, "scripts": { "start": "nodemon ./bin/www", - "test": "clear; jasmine-node --verbose spec/" + "test": "istanbul cover --include-all-sources jasmine-node test", + "db:drop": "dropdb video-store-api", + "db:create": "createdb video-store-api", + "db:schema": "node tasks/load_schema.js", + "db:seed": "node tasks/seed.js", + "db:reset": "npm run db:drop; npm run db:create; npm run db:schema; npm run db:seed", + "test": "clear; ./node_modules/.bin/istanbul cover -x 'spec/**/*' -- ./node_modules/.bin/jasmine-node --captureExceptions --verbose spec/" }, "dependencies": { "body-parser": "~1.13.2", "cookie-parser": "~1.3.5", "debug": "~2.2.0", "express": "~4.13.1", + "istanbul": "^0.4.4", "jade": "~1.11.0", + "jasmine-node": "^1.14.5", + "massive": "^2.3.0", "morgan": "~1.6.1", - "sequelize": "^3.23.3", "serve-favicon": "~2.3.0" }, "devDependencies": { diff --git a/routes/index.js b/routes/index.js index 06cfc1137..baf891ab3 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,9 +1,81 @@ -var express = require('express'); -var router = express.Router(); +var express = require('express') +var router = express.Router() +var movies_controller = require('../controllers/movies_controller') +var customers_controller = require('../controllers/customers_controller') +var rentals_controller = require('../controllers/rentals_controller') -/* GET home page. */ router.get('/', function(req, res, next) { res.status(200).json({whatevs: 'whatevs!!!'}) -}); +}) -module.exports = router; +router.get('/movies', function(req, res, next) { + movies_controller.index(req, res, next) +}) + +router.get('/movies/sort/:column_name', function(req, res, next) { + movies_controller.sort(req, res, next) +}) + +router.get('/movies/:title/current', +function(req, res, next) { + movies_controller.current(req, res, next) +}) + +router.get('/movies/:title/history/sort/:column_name',function(req, res, next){ + movies_controller.history(req, res, next) +}) + +router.get('/customers', function(req, res, next){ + customers_controller.index(req, res, next) +}) + +router.get('/customers/sort/:column_name', function(req, res, next) { + customers_controller.sort(req, res, next) +}) + +router.get('/customers/:id/current', function(req, res, next){ + customers_controller.current(req, res, next) +}) + +router.get('/customers/:id/history', +function(req, res, next) { + customers_controller.history(req, res, next) +}) + +//TO DO +router.get('/rentals/:title', +function(req, res, next) { + rentals_controller.view(req, res, next) +}) + +router.get('/rentals/:title/customers', +function(req, res, next) { + rentals_controller.customers(req, res, next) +}) + +router.get('/rentals/:title/check-out/:customer_id', +function(req, res, next) { + rentals_controller.check_out(req, res, next) +}) + +router.post('/rentals/:title/return/:customer_id', +function(req, res, next) { + rentals_controller.return_rental(req, res, next) +}) + +router.get('/rentals/overdue', +function(req, res, next) { + rentals_controller.overdue(req, res, next) +}) + +router.get('/api/docs', +function(req, res, next) { + res.render('docs', { title: 'API Docs - HTML'}) +}) + +router.get('/api/docs.json', +function(req,res) { + res.render('docs_json') +}) + +module.exports = router diff --git a/routes/zomg.js b/routes/zomg.js new file mode 100644 index 000000000..98992695d --- /dev/null +++ b/routes/zomg.js @@ -0,0 +1,34 @@ +// Needed API endpoints w/HTTP verbs +// +// GET (/customers) +// +// GET (/customers/sort/name?n=10&p=2) +// name (n) +// registered_at (r) +// postal_code (p) +// GET (/customers/:id/current) +// GET (/customers/:id/history) +// +// GET (/movies) +// GET (/movies/sort/release-date?n=5&p=1) +// title +// release_date +// GET (/movies/:title/current) +// GET (/movies/:title/history/sort/name) +// +// GET (/rentals/:title) +// GET (/rentals/:title/customers) +// UPDATE (/rentals/:id/:title/check-out) +// UPDATE (/rentals/:id/:title/return) +// GET (/rentals/overdue) + +var express = require('express'); +var router = express.Router(); +var locals = {} + +/* GET home page. */ +router.get('/', function(req, res, next) { + res.status(200).json({whatevs: 'zomg!!!'}) +}); + +module.exports = router; diff --git a/spec/controllers/customers.spec.js b/spec/controllers/customers.spec.js new file mode 100644 index 000000000..2f9a29263 --- /dev/null +++ b/spec/controllers/customers.spec.js @@ -0,0 +1,108 @@ +var request = require('request') +var base_url = "http://localhost:3000/customers" + + +describe("#index", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers", function(error, response, body) { + expect(response.statusCode).toBe(200) + done() + }) + }) + + + it("should be json", function(done) { + request.get("http://localhost:3000/customers", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers", function(error, response, body) { + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') + done() + }) + }) +}) + +describe("#sort", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers/sort/id", function(error, response, body) { + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("should be json", function(done) { + request.get("http://localhost:3000/customers/sort/id", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers/sort/id", function(error, response, body) { + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') + done() + }) + }) + +}) + + + +describe("#current", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers/12/current", function(error, response, body) { + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("should be json", function(done) { + request.get("http://localhost:3000/customers/12/current", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers/12/current", function(error, response, body) { + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') + done() + }) + }) + + }) + + + describe("#history", function() { + it("returns a Success response", function(done) { + request.get("http://localhost:3000/customers/47/history", function(error, response, body) { + expect(response.statusCode).toBe(200) + done() + }) + }) + + it("should be json", function(done) { + request.get("http://localhost:3000/customers/47/history", function(error, response, body) { + expect(response.headers['content-type']).toContain('application/json') + done() + }) + }) + + + it("should be an array of objects", function(done) { + request.get("http://localhost:3000/customers/47/history", function(error, response, body) { + var customers = JSON.parse(body) + expect(typeof customers).toEqual('object') + done() + }) + }) + + }) diff --git a/spec/controllers/movies.spec.js b/spec/controllers/movies.spec.js index ddcaf2f68..7f64967fa 100644 --- a/spec/controllers/movies.spec.js +++ b/spec/controllers/movies.spec.js @@ -1,5 +1,44 @@ -var request = require('request'); - +var request = require('request') +var base_url = "http://localhost:3000/movies" describe("Endpoints under /movies", function() { - + it('responds with a 200 status code', function (done){ + request.get(base_url, function(error, response, body){ + expect(response.statusCode).toEqual(200) + done() + }) + }) + + describe("the returned json data", function() { + it('is an array', function(done) { + request.get(base_url, function(error, response, body) { + var movies = JSON.parse(body)[0] + expect(typeof movies).toEqual('object') + done() + }) + }) + + it('has the right values for the keys', function(done) { + request.get(base_url, function(error, response, body) { + var movies = JSON.parse(body)[0]['id'] + expect(movies.title).toEqual("Psycho") + done() + }) + }) + + it('has the right values for the keys', function(done) { + request.get(base_url, function(error, response, body) { + var movies = JSON.parse(body)[0]['id'] + expect(movies.overview).toEqual("When larcenous real estate clerk Marion Crane goes on the lam with a wad of cash and hopes of starting a new life, she ends up at the notorious Bates Motel, where manager Norman Bates cares for his housebound mother. The place seems quirky, but fine… until Marion decides to take a shower.") + done() + }) + }) + + + + }) + + + + + }) diff --git a/spec/models/customer.spec.js b/spec/models/customer.spec.js new file mode 100644 index 000000000..119c37bad --- /dev/null +++ b/spec/models/customer.spec.js @@ -0,0 +1,72 @@ +var app = require('../../app') +var db = app.get('db') +var Customer = require('../../models/customer') + +describe('Customer', function () { + beforeEach(function(){ + + }) + + afterEach(function () { + db.end() + }) + + + describe('#all', function () { + it('should return an array of objects', function(done) { + Customer.all(function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + + }) + + it('should retern the right amount of customers', function(done) { + Customer.all(function(error,customers){ + expect(customers.length).toBeGreaterThan(199) + done() + }) + }) + + }) + + describe("#sort", function(){ + it('should return an array of objects', function(done){ + Customer.sort('name',10,5,3,function(error,customers){ + expect(customers).toEqual(jasmine.any(Array)) + done() + }) + }) + + it('be a certain lenght', function(done){ + Customer.sort('name',10,5,3, function(error,customers){ + expect(customers.length).toEqual(5) + done() + }) + }) + + it('it must sort by name', function(done){ + Customer.sort('name',10,5,3, function(error,customers){ + expect(customers[0]['id']['name']).toEqual('Acton Gilliam') + done() + }) + }) + + + it('if must be an address', function(done){ + Customer.sort('address',10,5,3, function(error,customers){ + expect(customers[0]['id']['address']).toEqual('121 Porta Ave') + done() + }) + }) + + it('should give an error if column does not exist', function(done){ + Customer.sort('candy',10,5,3, function(error,customers){ + expect(error.message).toEqual('column "candy" does not exist') + done() + }) + }) + + }) + +}) diff --git a/tasks/db_create.js b/tasks/db_create.js new file mode 100644 index 000000000..3e0d40466 --- /dev/null +++ b/tasks/db_create.js @@ -0,0 +1,14 @@ +var massive = require('massive') +var connectionString = "postgres://localhost/video-store-api" + +var db = massive.connectSync({connectionString : connectionString}) + +db.run(“CREATE DATABASE "video-store-api";”, function(err, res){ +}if (err){ throw(newError(err.message))} +console.log(res) +process.exit() +}) + + console.log("yay new DATABASE") + process.exit() +}) diff --git a/tasks/db_drop.js b/tasks/db_drop.js new file mode 100644 index 000000000..1bbbdc053 --- /dev/null +++ b/tasks/db_drop.js @@ -0,0 +1,12 @@ +var massive = require(‘massive’) +var connectionString = "postgres://localhost/video-store-api" +var db = massive.connectSync({connectionString : connectionString}) + +db.setup.schema([],function(err,res)){ + if(err){ + } throw(new Error(err.message)) +} + +console.log(“yay schema!”) +process.exit() +}) diff --git a/tasks/load_schema.js b/tasks/load_schema.js new file mode 100644 index 000000000..e2957024a --- /dev/null +++ b/tasks/load_schema.js @@ -0,0 +1,13 @@ +var massive = require("massive") +var connectionString = "postgres://localhost/video-store-api" + +var db = massive.connectSync({connectionString : connectionString}) + +db.setup.schema([], function(err, res) { + if (err) { + throw new Error(err.message) + } + + console.log("yay schema!") + process.exit() +}) diff --git a/tasks/seed.js b/tasks/seed.js new file mode 100644 index 000000000..678bfdefa --- /dev/null +++ b/tasks/seed.js @@ -0,0 +1,23 @@ +var massive = require('massive') +var connectionString = 'postgres://localhost/video-store-api' +var db = massive.connectSync({connectionString : connectionString}) +var movies = require('../db/seeds/movies.json') +var customers = require('../db/seeds/customers.json') +var rentals = require('../db/seeds/rentals.json') + +for (var movie of movies) { + console.log(movie) + db.movies.saveSync(movie) +} + +for (var customer of customers) { + console.log(customer) + db.customers.saveSync(customer) +} + +for (var rental of rentals) { + console.log(rental) + db.rentals.saveSync(rental) +} + +process.exit() diff --git a/tasks/sql_commands.js b/tasks/sql_commands.js new file mode 100644 index 000000000..b574de40a --- /dev/null +++ b/tasks/sql_commands.js @@ -0,0 +1,4 @@ +var customersRentalsquery = customers.query('SELECT id, name FROM customers'); + query.on('row',function(row){ + console.log('row.id, row.name') + }); diff --git a/views/docs.html b/views/docs.html new file mode 100644 index 000000000..36d70ab2f --- /dev/null +++ b/views/docs.html @@ -0,0 +1,163 @@ + + + + +

Video Store API

+ +
    +
  • +

    Movies

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    EndpointHTTP VerbRequired ParamsOptional ParamsNotes
    /moviesGETNoneNone
    /movies/sort/:column_nameGETMust include one of the sort paramsCan include n (number of results) or p (offset)Sort params: title, release date
    /movies/:title/currentGETMovie titleNoneReturns current renters' name, phone number, account credit
    /movies/:title/history/sort/:column_nameGETMovie title, one of two sort paramsNoneReturns past renters' name, phone number, account credit- sort by customer name or check out date
    +
  • +
  • +

    Customers

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

    Rentals

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

    Docs

    + + + + + + + + + + + + + + + + + + + + + + + +
    EndpointHTTP VerbRequired ParamsOptional ParamsNotes
    /api/docsGETNoneNoneYou're looking at it!
    /api/docs.jsonGETNoneNoneUnfinished - would render this page's info in JSON.
    +
  • + + diff --git a/views/docs_json.html b/views/docs_json.html new file mode 100644 index 000000000..b4a111ac7 --- /dev/null +++ b/views/docs_json.html @@ -0,0 +1,34 @@ + + + Express HTML + + + + + + +
    + +
    +

    Hello, world!

    +

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

    +

    Learn more

    +
    +
    + +