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

Alex-Willenbrink's Solution' #9

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules

config
32 changes: 32 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const express = require("express");
const app = express();

const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));

const session = require("express-session");
app.use(
session({
secret: "12345",
resave: false,
saveUninitialized: true
})
);

// const session = require("cookie-session");
// app.use(session({
// name: 'session'
// }))
const exhbs = require("express-handlebars");
const hbs = exhbs.create({ defaultLayout: "main" });
app.engine("handlebars", hbs.engine);
app.set("view engine", "handlebars");

const vikingRoutes = require("./routes");
app.use('/', vikingRoutes);



app.listen(3000, () => {
console.log("I'm listening");
});
19 changes: 19 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"development": {
"username": "postgres",
"password": "password",
"database": "database_development",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "postgres",
"password": "password",
"database": "database_test",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"dialect": "postgres"
}
}
62 changes: 62 additions & 0 deletions migrations/20170807171419-create-profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("Profiles", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userid: {
type: Sequelize.INTEGER
},
fname: {
type: Sequelize.STRING
},
lname: {
type: Sequelize.STRING
},
age: {
type: Sequelize.INTEGER
},
city: {
type: Sequelize.STRING
},
distance: {
type: Sequelize.INTEGER
},
gender: {
type: Sequelize.STRING
},
mstatus: {
type: Sequelize.STRING
},
height: {
type: Sequelize.INTEGER
},
children: {
type: Sequelize.INTEGER
},
occupation: {
type: Sequelize.STRING
},
education: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable("Profiles");
}
};
32 changes: 32 additions & 0 deletions migrations/20170807205857-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('Users', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
email: {
type: Sequelize.STRING
},
username: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable('Users');
}
};
32 changes: 32 additions & 0 deletions migrations/20170807215154-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("Users", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
email: {
type: Sequelize.STRING
},
username: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable("Users");
}
};
62 changes: 62 additions & 0 deletions migrations/20170807215358-create-profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("Profiles", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
fname: {
type: Sequelize.STRING
},
lname: {
type: Sequelize.STRING
},
userid: {
type: Sequelize.INTEGER
},
age: {
type: Sequelize.INTEGER
},
city: {
type: Sequelize.STRING
},
distance: {
type: Sequelize.INTEGER
},
gender: {
type: Sequelize.STRING
},
mstatus: {
type: Sequelize.STRING
},
height: {
type: Sequelize.INTEGER
},
children: {
type: Sequelize.INTEGER
},
occupation: {
type: Sequelize.STRING
},
education: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.fn("NOW")
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.dropTable("Profiles");
}
};
36 changes: 36 additions & 0 deletions models/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(module.filename);
var env = process.env.NODE_ENV || 'development';
var config = require(__dirname + '/../config/config.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(function(file) {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(function(file) {
var model = sequelize['import'](path.join(__dirname, file));
db[model.name] = model;
});

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

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

module.exports = db;
26 changes: 26 additions & 0 deletions models/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

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

module.exports = function(sequelize, DataTypes) {
var Profile = sequelize.define("Profile", {
fname: DataTypes.STRING,
lname: DataTypes.STRING,
userid: DataTypes.INTEGER,
age: DataTypes.INTEGER,
city: DataTypes.STRING,
distance: DataTypes.INTEGER,
gender: DataTypes.STRING,
mstatus: DataTypes.STRING,
height: DataTypes.INTEGER,
children: DataTypes.INTEGER,
occupation: DataTypes.STRING,
education: DataTypes.STRING
});
Profile.associate = function(models) {
Profile.belongsTo(models.User, {
foreignKey: "userid"
});
};
return Profile;
};
14 changes: 14 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
email: DataTypes.STRING,
username: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return User;
};
39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "assignment_okodin",
"version": "1.0.0",
"description": "Build a dating app so Viking thunder gods can find love <3",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "which nodemon > /dev/null && nodemon app.js || node app.js",
"console": "node repl.js",
"c": "node repl.js",
"seed": "sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all",
"seeds": "npm run sequelize db:migrate:undo:all && npm run sequelize db:migrate && npm run sequelize db:seed:all",
"sql": "node_modules/sequelize-cli/bin/sequelize"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gregfilipczak/assignment_okodin.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/gregfilipczak/assignment_okodin/issues"
},
"homepage": "https://github.com/gregfilipczak/assignment_okodin#readme",
"dependencies": {
"body-parser": "^1.17.2",
"cookie-session": "^1.3.0",
"express": "^4.15.4",
"express-method-override-get-post-support": "0.0.7",
"express-session": "^1.15.5",
"handlebars": "^4.0.10",
"method-override": "^2.3.9",
"morgan": "^1.8.2",
"morgan-toolkit": "^1.0.2",
"pg": "^6.4.1",
"pg-hstore": "^2.3.2",
"sequelize": "^4.4.2"
}
}
Loading