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

Avonyel's Solution' #10

Open
wants to merge 12 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
config/stupidworkaround.js
48 changes: 48 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const express = require("express");
const app = express();

const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const cookieSession = require("cookie-session");
const exphbs = require("express-handlebars");
const index = require("./routers/index");
const usersRouter = require("./routers/users");

//bodyParser
app.use(bodyParser.urlencoded({ extended: true }));

app.use(cookieParser());

//Sessions
app.use(
cookieSession({
name: "session",
// keys: ["I LOVE CATS"]
secret: "I LOVE CATS"
})
);

//views
const hbs = exphbs.create({
partialsDir: "views/",
defaultLayout: "main"
});
app.engine("handlebars", hbs.engine);
app.set("view engine", "handlebars");

//signup route
app.use("/", index);
app.use("/users", usersRouter);

//run the 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);
25 changes: 25 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let user = require("./stupidworkaround");

module.exports = {
development: {
username: user.username,
password: user.password,
database: "okodin_development",
host: "127.0.0.1",
dialect: "postgres"
},
test: {
username: user.name,
password: user.password,
database: "okodin_test",
host: "127.0.0.1",
dialect: "postgres"
},
production: {
username: "root",
password: null,
database: "okodin_production",
host: "127.0.0.1",
dialect: "postgres"
}
};
4 changes: 4 additions & 0 deletions config/stupidworkaround.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
name: "stephanie",
password: "MyKirigiri0"
};
30 changes: 30 additions & 0 deletions data_modeling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
User
id
username
email
profile_id

Profile
id
about
talents
favorite_things
why
user_id
age
location_id
gender
relationship_status
education
kids
height
occupation

Location
id
name
coordinate

sequelize model:create --name Location --attributes 'name:string coordinate:integer'

sequelize model:create --name Profile --attributes 'about:text talents:text favorite_things:text why:text user_id:integer age:integer location_id:integer gender:string relationship_status:string education:string kids:integer height:integer occupation:string'
37 changes: 37 additions & 0 deletions migrations/20170807170345-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("Users", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
username: {
type: Sequelize.STRING,
allowNull: false
},
email: {
type: Sequelize.STRING,
allowNull: false
},
profile_id: {
type: Sequelize.INTEGER
},
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");
}
};
65 changes: 65 additions & 0 deletions migrations/20170807172148-create-profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("Profiles", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
about: {
type: Sequelize.TEXT
},
talents: {
type: Sequelize.TEXT
},
favorite_things: {
type: Sequelize.TEXT
},
why: {
type: Sequelize.TEXT
},
user_id: {
type: Sequelize.INTEGER
},
age: {
type: Sequelize.INTEGER
},
location_id: {
type: Sequelize.INTEGER
},
gender: {
type: Sequelize.STRING
},
relationship_status: {
type: Sequelize.STRING
},
education: {
type: Sequelize.STRING
},
kids: {
type: Sequelize.INTEGER
},
height: {
type: Sequelize.INTEGER
},
occupation: {
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/20170807172323-create-location.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("Locations", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
coordinate: {
type: Sequelize.INTEGER
},
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("Locations");
}
};
43 changes: 43 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"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.js")[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;
14 changes: 14 additions & 0 deletions models/location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var Location = sequelize.define('Location', {
name: DataTypes.STRING,
coordinate: DataTypes.INTEGER
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return Location;
};
43 changes: 43 additions & 0 deletions models/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
var Profile = sequelize.define(
"Profile",
{
about: DataTypes.TEXT,
talents: DataTypes.TEXT,
favorite_things: DataTypes.TEXT,
why: DataTypes.TEXT,
user_id: DataTypes.INTEGER,
age: {
type: DataTypes.INTEGER,
validate: {
isInt: {
msg: "Age must be an integer"
}
}
},
location_id: DataTypes.INTEGER,
gender: DataTypes.STRING,
relationship_status: DataTypes.STRING,
education: DataTypes.STRING,
kids: DataTypes.INTEGER,
height: {
type: DataTypes.INTEGER,
validate: {
isInt: {
msg: "Height must be an integer"
}
}
},
occupation: DataTypes.STRING
},
{
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
}
);
return Profile;
};
29 changes: 29 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User", {
username: {
type: DataTypes.STRING,

validate: {
notEmpty: {
msg: "Username cannot be empty"
}
}
},
email: {
type: DataTypes.STRING,

validate: {
notEmpty: {
msg: "Username cannot be empty"
},
isEmail: {
msg: "Invalid email."
}
}
},

profile_id: DataTypes.INTEGER
});
return User;
};
1 change: 1 addition & 0 deletions node_modules/.bin/css-beautify

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

1 change: 1 addition & 0 deletions node_modules/.bin/editorconfig

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

1 change: 1 addition & 0 deletions node_modules/.bin/env-cmd

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

1 change: 1 addition & 0 deletions node_modules/.bin/gulp

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

1 change: 1 addition & 0 deletions node_modules/.bin/handlebars

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

Loading