Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greg's Market #16

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cb3a3c3
init commit
coelacanth7 Nov 15, 2017
188b417
set up basic structure
coelacanth7 Nov 15, 2017
565178b
hey
coelacanth7 Nov 15, 2017
d024c9e
remove node_modules oops
coelacanth7 Nov 15, 2017
144a6a7
models migrations in sql seeded
coelacanth7 Nov 15, 2017
109e47e
fixed a bug in my sequelize code
coelacanth7 Nov 15, 2017
fc486f8
can do some searches
coelacanth7 Nov 16, 2017
7e821f4
search is good but ugly
coelacanth7 Nov 16, 2017
8909c69
product show page
coelacanth7 Nov 16, 2017
fadb5d2
added some cart features
coelacanth7 Nov 17, 2017
c3f0920
added update cart
coelacanth7 Nov 17, 2017
8a0356e
all cart functions working right
coelacanth7 Nov 17, 2017
14d38bb
fixed cart
coelacanth7 Nov 17, 2017
1e9fa9b
can checkout almost
coelacanth7 Nov 17, 2017
68b1d5a
can checkout and insert into db
coelacanth7 Nov 20, 2017
bf6c3e9
can show checkout page
coelacanth7 Nov 20, 2017
b9ad541
failed to make seeds
coelacanth7 Nov 21, 2017
7dcee7a
admin index page
coelacanth7 Nov 21, 2017
7d72b9d
can show order
coelacanth7 Nov 21, 2017
f4fda9f
admin analytics complete
coelacanth7 Nov 22, 2017
852fc3d
done
coelacanth7 Nov 22, 2017
279a15b
procfile
coelacanth7 Mar 8, 2018
5ab15e3
json config update
coelacanth7 Mar 8, 2018
48cef83
promise bug fix
coelacanth7 Mar 8, 2018
7b24b8b
heroku
coelacanth7 Mar 8, 2018
8651a94
mongo json update for mongolab
coelacanth7 Mar 8, 2018
d80ad11
mongo variable update
coelacanth7 Mar 8, 2018
e1df3ba
debug
coelacanth7 Mar 8, 2018
56b1785
order by catergory
coelacanth7 Mar 8, 2018
11af19e
mg seeder broken
coelacanth7 Mar 11, 2018
d779e5f
added some functional flash messages
coelacanth7 Mar 11, 2018
e5b1363
added interesting images to products
coelacanth7 Mar 11, 2018
f319624
added some icons in navbar
coelacanth7 Mar 11, 2018
48c64d1
added some better styles
coelacanth7 Mar 11, 2018
5d3a8a3
title
coelacanth7 Mar 11, 2018
e1eafea
update readme
coelacanth7 Mar 11, 2018
6fffa3c
table responsive fix
coelacanth7 Mar 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
17 changes: 17 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var path = require('path');

// Set options
var config = {
"config": "./config/sequelize.json",
"migrations-path": "./migrations/sequelize",
"seeders-path": "./seeds/sequelize",
"models-path": "./models/sequelize"
};

// Resolve paths to absolute paths
Object.keys(config).forEach((key) => {
config[key] = path.resolve(config[key]);
});

// Export like any normal module
module.exports = config;
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node app.js
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# project_mimirs_market
A Viking eCommerce store for Thunder Gods that like to buy "Antique Wooden Pizzas"
# money burner

https://money-burner.herokuapp.com/

A fun e commerce app that integrates multiple technologies.

Gregory Alford

## Technologies used:

* Node
* Express
* Handlebars
* Mongoose
* Sequelize
* Stripe

## Deployment

Check it out:

https://money-burner.herokuapp.com/

## Description

You can search from 200 dynamically generated products, and filter by search queries, category, and price or sort by name, or price. Add these products to your cart and view similar items. Checkout and enter some fake info, a Visa card number 4242 4242 4242 4242 will pass. View orders from the Admin orders page. View Admin analytics where you can see data such as Revenue by State or category. Looks great on mobile also.
139 changes: 139 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// sequelize model:create --name Products --attributes "name:string sku:string description:string price:integer categoryId:integer"
// sequelize model:create --name Categories --attributes "name:string"
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}

var express = require("express");
var app = express();

// ----------------------------------------
// Body Parser
// ----------------------------------------
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));

// ----------------------------------------
// Sessions/Cookies
// ----------------------------------------
var cookieSession = require("cookie-session");

app.use(
cookieSession({
name: "session",
keys: ["asdf1234567890qwer"]
})
);

app.use((req, res, next) => {
req.session.cart = req.session.cart || [];
res.locals.session = req.session;
res.locals.cart = req.session.cart;

var cart = req.session.cart;
cart.quantity = cart.length;
next();
});

// ----------------------------------------
// Flash messages
// ----------------------------------------

var flash = require("express-flash-messages");
app.use(flash());

// ----------------------------------------
// Method Override
// ----------------------------------------
const methodOverride = require("method-override");
const getPostSupport = require("express-method-override-get-post-support");

app.use(
methodOverride(
getPostSupport.callback,
getPostSupport.options // { methods: ['POST', 'GET'] }
)
);

// ----------------------------------------
// Referrer
// ----------------------------------------
app.use((req, res, next) => {
req.session.backUrl = req.header("Referer") || "/";
next();
});

// ----------------------------------------
// Public
// ----------------------------------------
app.use(express.static(`${__dirname}/public`));

// ----------------------------------------
// Logging
// ----------------------------------------
var morgan = require("morgan");
var morganToolkit = require("morgan-toolkit")(morgan);

app.use(morganToolkit());

// ----------------------------------------
// Mongoose
// ----------------------------------------
const mongoose = require("mongoose");
app.use((req, res, next) => {
if (mongoose.connection.readyState) {
next();
} else {
require("./mongo")().then(() => next());
}
});

// ----------------------------------------
// Routes
// ----------------------------------------
var productsRouter = require("./routers/products");
app.use("/", productsRouter);

var cartRouter = require("./routers/cart");
app.use("/", cartRouter);

var checkoutRouter = require("./routers/checkout");
app.use("/", checkoutRouter);

var adminRouter = require("./routers/admin");
app.use("/", adminRouter);

// ----------------------------------------
// Template Engine
// ----------------------------------------
var expressHandlebars = require("express-handlebars");

var hbs = expressHandlebars.create({
partialsDir: "views/",
defaultLayout: "application",
helpers: {
photoId: id => Number(id) % 9
}
});

app.engine("handlebars", hbs.engine);
app.set("view engine", "handlebars");

// expressHandlebars.registerHelper("photoId", );

// ----------------------------------------
// Server
// ----------------------------------------
var port = process.env.PORT || process.argv[2] || 3000;
var host = "localhost";

var args;
process.env.NODE_ENV === "production" ? (args = [port]) : (args = [port, host]);

args.push(() => {
console.log(`Listening: http://${host}:${port}`);
});

app.listen.apply(app, args);

module.exports = app;
13 changes: 13 additions & 0 deletions config/mongoose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"development": {
"database": "project_mimirs_market_development",
"host": "localhost"
},
"test": {
"database": "project_mimirs_market_test",
"host": "localhost"
},
"production": {
"use_env_variable": "MONGOLAB_BRONZE_URI"
}
}
20 changes: 20 additions & 0 deletions config/sequelize.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"development": {
"username": "GREG",
"password": null,
"database": "project_mimirs_market_development",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "GREG",
"password": null,
"database": "project_mimirs_market_test",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"use_env_variable": "DATABASE_URL",
"dialect": "postgres"
}
}
41 changes: 41 additions & 0 deletions migrations/sequelize/20171115015756-create-products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"use strict";
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable("Products", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
sku: {
type: Sequelize.STRING
},
description: {
type: Sequelize.STRING
},
price: {
type: Sequelize.INTEGER
},
categoryId: {
type: Sequelize.INTEGER
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable("Products");
}
};
29 changes: 29 additions & 0 deletions migrations/sequelize/20171115015814-create-categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable("Categories", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable("Categories");
}
};
11 changes: 11 additions & 0 deletions models/mongoose/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require("mongoose");
const bluebird = require("bluebird");

mongoose.Promise = bluebird;

const models = {};

// Load models and attach to models here
models.Order = require("./order");

module.exports = models;
24 changes: 24 additions & 0 deletions models/mongoose/order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var OrderSchema = new Schema(
{
fname: String,
lname: String,
address: String,
city: String,
state: String,
zip: String,
total: Number,
orderedProducts: [],
stripe: {},
stripeToken: String
},
{
timestamps: true
}
);

var Order = mongoose.model("Order", OrderSchema);

module.exports = Order;
13 changes: 13 additions & 0 deletions models/sequelize/categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";
module.exports = (sequelize, DataTypes) => {
var Categories = sequelize.define("Categories", {
name: DataTypes.STRING
});

Categories.associate = function(models) {
Categories.hasMany(models.Products, {
foreignKey: "categoryId"
});
};
return Categories;
};
36 changes: 36 additions & 0 deletions models/sequelize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var fs = require('fs');
var path = require('path');
var Sequelize = require('sequelize');
var basename = path.basename(__filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../../config/sequelize.json')[env];
var db = {};

if (config.use_env_variable) {
var sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
var sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;
Loading