Skip to content

Commit

Permalink
Vidly first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikrant Rana committed Jun 21, 2021
0 parents commit da87755
Show file tree
Hide file tree
Showing 10,978 changed files with 1,397,575 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vidly_jwtPrivateKey=vidlySecureKey
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
4 changes: 4 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"jwtPrivateKey":"vidly_jwtPrivateKey",
"db":"mongodb://localhost/vidly"
}
4 changes: 4 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"jwtPrivateKey":"",
"db":"mongodb://localhost/vidly"
}
4 changes: 4 additions & 0 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"jwtPrivateKey":"vidly_jwtPrivateKey",
"db":"mongodb://localhost/vidly_test"
}
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const app = express();

require('./startup/logging')();
require('./startup/routes')(app);
require('./startup/db')();
require('./startup/config')();

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on port ${port}`));
31 changes: 31 additions & 0 deletions logfile.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{"message":"Could not get the genres","stack":"Error: Could not get the genres\n at E:\\Study\\node practise\\vidly\\routes\\genres.js:8:11\n at E:\\Study\\node practise\\vidly\\node_modules\\express-async-errors\\index.js:17:17\n at Layer.handle [as handle_request] (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\layer.js:95:5)\n at next (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\route.js:137:13)\n at Route.dispatch (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\route.js:112:3)\n at E:\\Study\\node practise\\vidly\\node_modules\\express-async-errors\\index.js:17:17\n at Layer.handle [as handle_request] (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\layer.js:95:5)\n at E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:281:22\n at Function.process_params (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:335:12)\n at next (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:275:10)\n at Function.handle (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:174:3)\n at router (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:47:12)\n at E:\\Study\\node practise\\vidly\\node_modules\\express-async-errors\\index.js:17:17\n at Layer.handle [as handle_request] (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\layer.js:95:5)\n at trim_prefix (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:317:13)\n at E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:284:7\n at Function.process_params (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:335:12)\n at next (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:275:10)\n at E:\\Study\\node practise\\vidly\\node_modules\\body-parser\\lib\\read.js:130:5\n at invokeCallback (E:\\Study\\node practise\\vidly\\node_modules\\raw-body\\index.js:224:16)\n at done (E:\\Study\\node practise\\vidly\\node_modules\\raw-body\\index.js:213:7)\n at IncomingMessage.onEnd (E:\\Study\\node practise\\vidly\\node_modules\\raw-body\\index.js:273:7)","level":"error","timestamp":"2021-05-13T06:32:23.951Z"}
{"message":"Could not get the genres","stack":"Error: Could not get the genres\n at E:\\Study\\node practise\\vidly\\routes\\genres.js:8:11\n at E:\\Study\\node practise\\vidly\\node_modules\\express-async-errors\\index.js:17:17\n at Layer.handle [as handle_request] (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\layer.js:95:5)\n at next (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\route.js:137:13)\n at Route.dispatch (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\route.js:112:3)\n at E:\\Study\\node practise\\vidly\\node_modules\\express-async-errors\\index.js:17:17\n at Layer.handle [as handle_request] (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\layer.js:95:5)\n at E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:281:22\n at Function.process_params (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:335:12)\n at next (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:275:10)\n at Function.handle (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:174:3)\n at router (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:47:12)\n at E:\\Study\\node practise\\vidly\\node_modules\\express-async-errors\\index.js:17:17\n at Layer.handle [as handle_request] (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\layer.js:95:5)\n at trim_prefix (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:317:13)\n at E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:284:7\n at Function.process_params (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:335:12)\n at next (E:\\Study\\node practise\\vidly\\node_modules\\express\\lib\\router\\index.js:275:10)\n at E:\\Study\\node practise\\vidly\\node_modules\\body-parser\\lib\\read.js:130:5\n at invokeCallback (E:\\Study\\node practise\\vidly\\node_modules\\raw-body\\index.js:224:16)\n at done (E:\\Study\\node practise\\vidly\\node_modules\\raw-body\\index.js:213:7)\n at IncomingMessage.onEnd (E:\\Study\\node practise\\vidly\\node_modules\\raw-body\\index.js:273:7)","level":"error","timestamp":"2021-05-13T06:33:01.930Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:21:11.974Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:23:05.767Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:26:31.841Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:27:45.281Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:29:14.076Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:29:18.274Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:30:10.371Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:30:46.769Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:31:11.002Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:31:36.511Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:32:00.109Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:33:18.208Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:33:30.028Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:47:19.192Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:47:44.273Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:49:25.865Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:51:11.261Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:52:29.343Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:52:49.010Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:53:23.822Z"}
{"level":"info","message":"Connected to mongodb...","timestamp":"2021-05-15T10:53:52.847Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:02:14.521Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:03:52.853Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:04:16.659Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:05:29.257Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:06:02.998Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:07:10.242Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:07:49.662Z"}
{"level":"info","message":"Connected to mongodb://localhost/vidly...","timestamp":"2021-05-15T11:08:22.588Z"}
4 changes: 4 additions & 0 deletions middleware/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function(req, res, next) {
if(!req.user.isAdmin) return res.status(403).send('Access denied');
next();
}
9 changes: 9 additions & 0 deletions middleware/async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function (handler) {
return async (req, res, next) => {
try{
await handler(req, res);
} catch(ex) {
next(ex);
}
};
}
17 changes: 17 additions & 0 deletions middleware/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const jwt = require('jsonwebtoken');
const dotenv = require('dotenv');

function auth(req, res, next) {
const token = req.header('x-auth-token');
if (!token) return res.status(401).send('Access denied. No token provided');

try{
const decoded = jwt.verify(token, process.env.vidly_jwtPrivateKey);
req.user = decoded;
next();
} catch (err) {
res.status(400).send('Invalid token');
}
}

module.exports = auth;
6 changes: 6 additions & 0 deletions middleware/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const winston = require('winston');

module.exports = function(err, req, res, next) {
winston.error(err.message, err);
res.status(500).send('Something went wrong!!');
}
34 changes: 34 additions & 0 deletions models/customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Joi = require('joi');
const mongoose = require('mongoose');

const Customer = mongoose.model('Customer', new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 50
},
isGold: {
type: Boolean,
default: false
},
phone: {
type: String,
required: true,
minlength: 5,
maxlength: 50
}
}));

function validateCustomer(customer) {
const schema = {
name: Joi.string().min(5).max(50).required(),
phone: Joi.string().min(5).max(50).required(),
isGold: Joi.boolean(),
};

return Joi.validate(customer, schema);
}

exports.Customer = Customer;
exports.validate = validateCustomer;
25 changes: 25 additions & 0 deletions models/genre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Joi = require('joi');
const mongoose = require('mongoose');

const genreSchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 50
}
});

const Genre = mongoose.model('Genre', genreSchema);

function validateGenre(genre) {
const schema = {
name: Joi.string().min(3).required()
};

return Joi.validate(genre, schema);
}

exports.genreSchema = genreSchema;
exports.Genre = Genre;
exports.validate = validateGenre;
43 changes: 43 additions & 0 deletions models/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const Joi = require('joi');
const mongoose = require('mongoose');
const {genreSchema} = require('./genre');

const Movie = mongoose.model('Movie', new mongoose.Schema({
title: {
type: String,
required: true,
trim: true,
minlength: 5,
maxlength: 255
},
genre: {
type: genreSchema,
required: true
},
numberInStock: {
type: Number,
required: true,
min: 5,
max: 255
},
dailyRentalRate: {
type: Number,
required: true,
min: 5,
max: 255
}
}));

function validateMovie(movie) {
const schema = {
title: Joi.string().min(5).max(50).required(),
genreId: Joi.string().required(),
numberInStock: Joi.number().min(0).required(),
dailyRentalRate: Joi.number().min(0).required()
};

return Joi.validate(movie, schema);
}

exports.Movie = Movie;
exports.validate = validateMovie;
68 changes: 68 additions & 0 deletions models/rental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const Joi = require('joi');
const mongoose = require('mongoose');

const Rental = mongoose.model('Rental', new mongoose.Schema({
customer: {
type: new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 50
},
isGold: {
type: Boolean,
default: false
},
phone: {
type: String,
required: true,
minlength: 5,
maxlength: 50
}
}),
required: true
},
movie:{
type: new mongoose.Schema({
title: {
type: String,
required: true,
trim: true,
minlength: 5,
maxlength: 255
},
dailyRentalRate: {
type: Number,
required: true,
min: 5,
max: 255
}
}),
required: true
},
dateOut: {
type: Date,
required: true,
default: Date.now
},
dateReturned: {
type: Date,
},
rentalFee: {
type: Number,
min: 0
}
}));

function validateRental(rental) {
const schema = {
customerId: Joi.string().required(),
movieId: Joi.string().required(),
};

return Joi.validate(rental, schema);
}

exports.Rental = Rental;
exports.validate = validateRental;
46 changes: 46 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const jwt = require('jsonwebtoken');
const Joi = require('joi');
const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 5,
maxlength: 50
},
email: {
type: String,
required: true,
minlength: 5,
maxlength: 255,
unique: true
},
password: {
type: String,
required: true,
minlength: 5,
maxlength: 1024
},
isAdmin: Boolean
});

userSchema.methods.generateAuthenticationToken = function() {
const token = jwt.sign({ _id: this._id, isAdmin: this.isAdmin}, process.env.vidly_jwtPrivateKey);
return token;
}

const User = mongoose.model('User', userSchema);

function validateUser(user) {
const schema = {
name: Joi.string().min(5).max(50).required(),
email: Joi.string().min(5).max(255).required().email(),
password: Joi.string().min(5).max(255).required()
};

return Joi.validate(user, schema);
}

exports.User = User;
exports.validate = validateUser;
15 changes: 15 additions & 0 deletions node_modules/.bin/acorn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/acorn.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions node_modules/.bin/acorn.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit da87755

Please sign in to comment.