-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan Roth
committed
Aug 3, 2020
1 parent
07d7e91
commit 2d4a4c3
Showing
187 changed files
with
44,693 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ var mongoose = require('mongoose') | |
var path = require('path') | ||
var bodyParser = require('body-parser') | ||
var session = require('express-session') | ||
var cookieParser = require('cookie-parser') | ||
|
||
var indexRouter = require('./routes/index') | ||
var usersRouter = require('./routes/users') | ||
var adminRouter = require('./routes/admin') | ||
var basketRouter = require('./routes/basket') | ||
|
||
var app = express() | ||
|
||
|
@@ -17,24 +18,24 @@ var uri = 'mongodb+srv://app-user:[email protected]/bookstore?retry | |
app.set('views', path.join(__dirname, 'views')) | ||
app.set('view engine', 'pug') | ||
|
||
app.use(express.static('public')) | ||
|
||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({ extended: false })) | ||
|
||
app.use(cookieParser()) | ||
app.use(session({ | ||
secret: 'secret', | ||
cookie: { | ||
maxAge: 60000, | ||
secure: false | ||
} | ||
})) | ||
|
||
app.use('/', indexRouter) | ||
app.use('/users', usersRouter) | ||
app.use('/basket', basketRouter) | ||
app.use('/admin', adminRouter) | ||
|
||
// app.use(session({ | ||
// secret: 'secret', | ||
// resave: false, | ||
// saveUninitialized: true, | ||
// cookie: { | ||
// secure: false, | ||
// httpOnly: true, | ||
// maxAge: 1000 * 60 * 60 * 24 | ||
// } | ||
// })) | ||
|
||
mongoose.connect(uri, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => console.log('Connected to MongoDB')) | ||
.catch(err => console.error("Couldn't connect to MongoDB: " + err)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var getBook = require('./getBook.js') | ||
|
||
const BookModel = require('../../models/book.js') | ||
|
||
var addBook = async function (isbn, title, price, author, genre, imagePath, stock) { | ||
if (await getBook({ isbn: isbn })) { | ||
console.log('Book is already in database') | ||
return | ||
} | ||
if (imagePath === null || imagePath === undefined) { | ||
imagePath = '/images/bookimages/placeholder.png' | ||
} | ||
var newBook = new BookModel({ isbn: isbn, title: title, price: price, author: author, genre: genre, image: imagePath, stock: stock }) | ||
newBook.save(function (err, book) { | ||
if (err) return console.error(err) | ||
console.log(book.title + ' added to database') | ||
}) | ||
} | ||
|
||
module.exports = addBook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var bookModel = require('../../models/book.js') | ||
|
||
var getBook = async function (filter) { | ||
return await bookModel.findOne(filter).exec().then(function (result) { | ||
if (result === null) { | ||
return false | ||
} | ||
if (result === undefined) { | ||
return false | ||
} | ||
return result | ||
}) | ||
} | ||
|
||
module.exports = getBook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var bookModel = require('../../models/book.js') | ||
|
||
var getBooks = async function (filter) { | ||
return await bookModel.find(filter).exec().then(function (result) { | ||
if (result === null) { | ||
return false | ||
} | ||
if (result === undefined) { | ||
return false | ||
} | ||
|
||
console.log(result) | ||
|
||
return result | ||
}) | ||
} | ||
|
||
module.exports = getBooks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var userModel = require('../../models/user.js') | ||
|
||
var getUser = async function (filter) { | ||
return await userModel.findOne(filter).exec().then(function (result) { | ||
if (result === null) { | ||
return false | ||
} | ||
if (result.username === undefined) { | ||
return false | ||
} | ||
return result | ||
}) | ||
} | ||
|
||
module.exports = getUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var getBook = require('./getBook') | ||
|
||
const BookModel = require('../../models/book.js') | ||
|
||
var removeBook = async function (isbn) { | ||
var hasBook = await getBook({ isbn: isbn }) | ||
if (hasBook === null || hasBook === undefined || hasBook === false) { | ||
console.log('Book does not exist!') | ||
return | ||
} | ||
await BookModel.findOneAndDelete({ isbn: isbn }, function (err, result) { | ||
if (err) return console.log(err) | ||
console.log(result.title + ' was removed from database!') | ||
}) | ||
} | ||
|
||
module.exports = removeBook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var getUser = require('./getUser') | ||
|
||
const UserModel = require('../../models/user.js') | ||
|
||
var removeUser = async function (username) { | ||
var hasUser = await getUser(username) | ||
if (hasUser === null || hasUser === undefined || hasUser === false) { | ||
console.log('User does not exist!') | ||
return | ||
} | ||
await UserModel.findOneAndDelete({ username: username }, function (err, result) { | ||
if (err) return console.log(err) | ||
console.log(result.username + ' was removed from database!') | ||
}) | ||
} | ||
|
||
module.exports = removeUser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var getBook = require('./getBook.js') | ||
|
||
const BookModel = require('../../models/book.js') | ||
|
||
var updateBook = async function (isbn, title, price, author, genre, imagePath, stock) { | ||
var book = await getBook({ isbn: isbn }) | ||
if (!book) { | ||
console.log('Book is not in the database!') | ||
return | ||
} | ||
|
||
BookModel.findOneAndUpdate({ isbn: book.isbn }, { title: title, price: price, author: author, genre: genre, image: imagePath, stock: stock }, function (err, book) { | ||
if (err) return console.error(err) | ||
console.log(book.title + ' was updated!') | ||
}) | ||
} | ||
|
||
module.exports = updateBook |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.