Skip to content

Commit

Permalink
Using yarn, added yarn.lock, refactored all var declarations to eithe…
Browse files Browse the repository at this point in the history
…r let or const, updated checkout page with lighter text along with footer
  • Loading branch information
Vincent440 committed Nov 8, 2019
1 parent c1774ba commit 5bd8bda
Show file tree
Hide file tree
Showing 11 changed files with 1,326 additions and 58 deletions.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@ To use this project, you'll need to do the following:

* run `npm i` from the terminal (this will install the npm modules: dotenv, bcrypt, connect-session-sequelize, express, express-handlebars, express-session, mysql2, passport, sequelize and validator)
* create the mysql database using the `schema.sql` file
* run 'server.js' to dynamically create the required tables
* seed the newly created database tables with the `seeds.sql` file
* create a `.env` file with your MySQL Database password in the following format
* (this was included in the `.gitignore` file to prevent the password from being exposed on Github):

```
PASSWORD="your_database_password_here"
```
This file will be imported by `config/index.js` On a local setup.

This works because `config/index.js` was modified in the following way:

```js
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
// assign the local password from the `.env` to a new password variable.
const password = process.env.PASSWORD;
sequelize = new Sequelize(config.database, config.username,/*config.password is now*/ password, config);
}
```
(this was included in the `.gitignore` file to prevent the password from being exposed on Github):
```
DB_PASSWORD="your_database_password_here"
```
This file will be imported by `config/index.js` while running on your computer locally because of the following changes to the `config/index.js` file.
```js
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
// assign the local password from the `.env` to a new password variable.
const password = process.env.DB_PASSWORD;
sequelize = new Sequelize(config.database, config.username,/*config.password is now*/ password, config);
}
```
* run 'server.js' to dynamically create the required tables
* seed the newly created database tables with the `seeds.sql` file
---
## Our MySQL database layout for this project:
![MySQL Layout](/public/images/project2_database.png)
![MySQL Layout](./public/images/project2_database.png)
---
Expand Down
16 changes: 8 additions & 8 deletions controllers/apiRoutes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";

var express = require("express");
var router = express.Router();
var passport = require("passport");
const express = require("express");
const router = express.Router();
const passport = require("passport");

const bcrypt = require('bcrypt');
const saltRounds = 10;

var db = require("../models");
const db = require("../models");

// delete an item from the cart
router.delete("/api/cart", (req, res) => {
Expand Down Expand Up @@ -69,8 +69,8 @@ router.post("/api/cart", (req, res) => {

// route for processing a submitted order
// set variables for submitting an order
var orderId = 0;
var userId = 0;
let orderId = 0;
let userId = 0;
// first find the cart that has been submitted
router.post("/api/cart/submitted", (req, res, next) => {
userId = req.user;
Expand All @@ -93,7 +93,7 @@ router.post("/api/cart/submitted", (req, res, next) => {
productId: element.productId
});
});
var order = {
let order = {
orderId: orderId
}
res.send(order);
Expand Down Expand Up @@ -165,7 +165,7 @@ router.post("/api/account/register", (req, res) => {
});

// login with an existing username and password
var pwd = "";
let pwd = "";
router.post("/api/account/login", (req, res) => {
pwd = req.body.password;
db.users.findOne({
Expand Down
22 changes: 11 additions & 11 deletions controllers/htmlRoutes.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use strict";

var express = require("express");
var router = express.Router();
const express = require("express");
const router = express.Router();
const Sequelize = require('sequelize');
const op = Sequelize.Op;

var db = require("../models");
const db = require("../models");

// find out if the user is looged in
router.get("/user/status", (req, res) => {
Expand All @@ -29,10 +29,10 @@ router.get("/cart/info", (req, res) => {
attributes: ['id', 'num', 'each_price', 'productId'],
where: { userId: req.user }
}).then(function (cart) {
var cartInfo = {};
var totalCost = 0;
var uniqueItems = 0;
var totalItems = 0;
let cartInfo = {};
let totalCost = 0;
let uniqueItems = 0;
let totalItems = 0;
cart.forEach(function (element) {
totalCost += element.num * element.each_price;
uniqueItems++;
Expand Down Expand Up @@ -180,11 +180,11 @@ router.get("/cart", (req, res) => {
{ model: db.products, attributes: ['name', 'description'] }
]
}).then(function (data) {
var totalCost = 0;
var totalItems = 0;
var cart = [];
let totalCost = 0;
let totalItems = 0;
let cart = [];
for (let i = 0; i < data.length; i++) {
var tempObj = {};
let tempObj = {};
totalItems += data[i].num;
totalCost += data[i].num * data[i].each_price;
tempObj.id = data[i].id;
Expand Down
2 changes: 1 addition & 1 deletion models/cart_item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (sequelize, DataTypes) {
var CartItem = sequelize.define("cart_items", {
let CartItem = sequelize.define("cart_items", {
num: {
type: DataTypes.INTEGER,
allowNull: false
Expand Down
2 changes: 1 addition & 1 deletion models/category.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (sequelize, DataTypes) {
var Category = sequelize.define("categories", {
let Category = sequelize.define("categories", {
name: {
type: DataTypes.STRING,
allowNull: false
Expand Down
2 changes: 1 addition & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
const password = process.env.PASSWORD;
const password = process.env.DB_PASSWORD;
sequelize = new Sequelize(config.database, config.username, password, config);
}

Expand Down
2 changes: 1 addition & 1 deletion models/order_item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function (sequelize, DataTypes) {
var OrderItem = sequelize.define("order_items", {
let OrderItem = sequelize.define("order_items", {
num: {
type: DataTypes.INTEGER,
allowNull: false
Expand Down
20 changes: 10 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"use strict";
require('dotenv').config()
var express = require("express");
var app = express();
const express = require("express");
const app = express();

var PORT = process.env.PORT || 3000;
const PORT = process.env.PORT || 3000;

var db = require("./models");
const db = require("./models");

app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(express.static("public"));

var session = require("express-session");
var passport = require("passport");
var SequelizeStore = require('connect-session-sequelize')(session.Store);
const session = require("express-session");
const passport = require("passport");
const SequelizeStore = require('connect-session-sequelize')(session.Store);

app.use(session({
secret: 'asdwelhjt',
Expand All @@ -29,15 +29,15 @@ app.use(session({
app.use(passport.initialize());
app.use(passport.session());

var exphbs = require("express-handlebars");
const exphbs = require("express-handlebars");

app.engine("handlebars", exphbs({ defaultLayout: "main" }));
app.set("view engine", "handlebars");

var apiRoutes = require("./controllers/apiRoutes.js");
const apiRoutes = require("./controllers/apiRoutes.js");
app.use(apiRoutes);

var htmlRoutes = require("./controllers/htmlRoutes.js");
const htmlRoutes = require("./controllers/htmlRoutes.js");
app.use(htmlRoutes);

db.sequelize.sync({ force: false }).then(function () {
Expand Down
4 changes: 2 additions & 2 deletions views/layouts/main.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

<nav class="navbar fixed-bottom navbar-light bg-dark p-0 justify-content-center">
<footer class="p-0">
<ul class="nav">
<ul class="nav text-muted">
<li class="nav-item p-0 d-none d-sm-inline ">
<span class="nav-link navbar-text py-1 px-auto">2019&#169;</span>
<span class="nav-link text-light navbar-text py-1 px-auto">2019&#169;</span>
</li>
<li class="nav-item p-0">
<a class="nav-link py-1 px-xs-1 px-auto" title="Visit Mike Gullo's Github Portfolio" href="https://mike14747.github.io/">Mike G.</a>
Expand Down
2 changes: 1 addition & 1 deletion views/partials/cart_view.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{{/if}}
</tbody>
</table>
<caption title="Viewing your shopping cart above"><i class="fas fa-arrow-circle-up"></i> Your Shopping Cart <i class="fas fa-shopping-cart"></i></caption>
<caption title="Viewing your shopping cart above" class=""><i class="fas fa-arrow-circle-up text-light"> Your Shopping Cart</i> <i class="fas fa-shopping-cart text-light"></i></caption>
{{!-- Make purchase button if there is a cart --}}
{{#if cart}}
<div class="m-auto w-50 px-2">
Expand Down
Loading

0 comments on commit 5bd8bda

Please sign in to comment.