From 5e238fb7866def6b16df619fc305c1d2c7ab1d15 Mon Sep 17 00:00:00 2001 From: Greg Filipczak Date: Mon, 7 Aug 2017 17:08:51 +0000 Subject: [PATCH 1/8] working on initial models --- .gitignore | 1 + config/config.json | 23 +++++++++++++++ migrations/20170807170646-create-user.js | 33 ++++++++++++++++++++++ models/index.js | 36 ++++++++++++++++++++++++ models/user.js | 15 ++++++++++ package.json | 32 +++++++++++++++++++++ schema.txt | 10 +++++++ 7 files changed, 150 insertions(+) create mode 100644 .gitignore create mode 100644 config/config.json create mode 100644 migrations/20170807170646-create-user.js create mode 100644 models/index.js create mode 100644 models/user.js create mode 100644 package.json create mode 100644 schema.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08b2553 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..0f858c6 --- /dev/null +++ b/config/config.json @@ -0,0 +1,23 @@ +{ + "development": { + "username": "root", + "password": null, + "database": "database_development", + "host": "127.0.0.1", + "dialect": "mysql" + }, + "test": { + "username": "root", + "password": null, + "database": "database_test", + "host": "127.0.0.1", + "dialect": "mysql" + }, + "production": { + "username": "root", + "password": null, + "database": "database_production", + "host": "127.0.0.1", + "dialect": "mysql" + } +} diff --git a/migrations/20170807170646-create-user.js b/migrations/20170807170646-create-user.js new file mode 100644 index 0000000..e407f70 --- /dev/null +++ b/migrations/20170807170646-create-user.js @@ -0,0 +1,33 @@ +'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 + }, + email: { + type: Sequelize.STRING + }, + profileId: { + type: Sequelize.INTEGER + }, + createdAt: { + allowNull: false, + type: Sequelize.DATE + }, + updatedAt: { + allowNull: false, + type: Sequelize.DATE + } + }); + }, + down: function(queryInterface, Sequelize) { + return queryInterface.dropTable('Users'); + } +}; \ No newline at end of file diff --git a/models/index.js b/models/index.js new file mode 100644 index 0000000..7540dba --- /dev/null +++ b/models/index.js @@ -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; diff --git a/models/user.js b/models/user.js new file mode 100644 index 0000000..b45d53d --- /dev/null +++ b/models/user.js @@ -0,0 +1,15 @@ +'use strict'; +module.exports = function(sequelize, DataTypes) { + var User = sequelize.define('User', { + username: DataTypes.STRING, + email: DataTypes.STRING, + profileId: DataTypes.INTEGER + }, { + classMethods: { + associate: function(models) { + // associations can be defined here + } + } + }); + return User; +}; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f9d4bb0 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "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" + }, + "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", + "handlebars": "^4.0.10", + "method-override": "^2.3.9", + "morgan": "^1.8.2", + "morgan-toolkit": "^1.0.2", + "pg": "^7.1.0", + "pg-hstore": "^2.3.2", + "sequelize": "^4.4.2" + } +} diff --git a/schema.txt b/schema.txt new file mode 100644 index 0000000..eb8293f --- /dev/null +++ b/schema.txt @@ -0,0 +1,10 @@ +User: username, email, ProfileID + +Profile: fname, lname, age, city, distance, gender, mstatus, height, children - INTEGER, occupation, education + +Pets: dogs, cats, horses, other + +ProfilePets: ProfileId, PetsId + + +sequelize model:create --name User --attributes "username:string email:string profileId:integer" From aafa554af10523b70267a12c5206bca58c1e2f0a Mon Sep 17 00:00:00 2001 From: Alex-Willenbrink Date: Mon, 7 Aug 2017 12:43:58 -0500 Subject: [PATCH 2/8] seeding trials --- app.js | 28 ++++++++++ config/config.json | 18 +++--- migrations/20170807170646-create-user.js | 8 ++- migrations/20170807171419-create-profile.js | 62 +++++++++++++++++++++ models/profile.js | 24 ++++++++ npm-debug.log | 49 ++++++++++++++++ package.json | 10 +++- seeders/20170807172759-User.js | 38 +++++++++++++ seeders/20170807172806-Profile.js | 47 ++++++++++++++++ 9 files changed, 269 insertions(+), 15 deletions(-) create mode 100644 app.js create mode 100644 migrations/20170807171419-create-profile.js create mode 100644 models/profile.js create mode 100644 npm-debug.log create mode 100644 seeders/20170807172759-User.js create mode 100644 seeders/20170807172806-Profile.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..6c5c6f5 --- /dev/null +++ b/app.js @@ -0,0 +1,28 @@ +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 = exbhs.create({ defaultLayout: "main" }); +app.engine("handlebars", hbs.engine); +app.set("view engine", "handlebars"); + + + +app.listen(3000, () => { + console.log("I'm listening"); +}) diff --git a/config/config.json b/config/config.json index 0f858c6..9a23407 100644 --- a/config/config.json +++ b/config/config.json @@ -1,23 +1,19 @@ { "development": { - "username": "root", - "password": null, + "username": "postgres", + "password": "password", "database": "database_development", "host": "127.0.0.1", - "dialect": "mysql" + "dialect": "postgres" }, "test": { - "username": "root", - "password": null, + "username": "postgres", + "password": "password", "database": "database_test", "host": "127.0.0.1", - "dialect": "mysql" + "dialect": "postgres" }, "production": { - "username": "root", - "password": null, - "database": "database_production", - "host": "127.0.0.1", - "dialect": "mysql" + "dialect": "postgres" } } diff --git a/migrations/20170807170646-create-user.js b/migrations/20170807170646-create-user.js index e407f70..cbf3203 100644 --- a/migrations/20170807170646-create-user.js +++ b/migrations/20170807170646-create-user.js @@ -19,15 +19,17 @@ module.exports = { }, createdAt: { allowNull: false, - type: Sequelize.DATE + type: Sequelize.DATE, + defaultValue: Sequelize.fn('NOW') }, updatedAt: { allowNull: false, - type: Sequelize.DATE + type: Sequelize.DATE, + defaultValue: Sequelize.fn('NOW') } }); }, down: function(queryInterface, Sequelize) { return queryInterface.dropTable('Users'); } -}; \ No newline at end of file +}; diff --git a/migrations/20170807171419-create-profile.js b/migrations/20170807171419-create-profile.js new file mode 100644 index 0000000..c9a7731 --- /dev/null +++ b/migrations/20170807171419-create-profile.js @@ -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'); + } +}; diff --git a/models/profile.js b/models/profile.js new file mode 100644 index 0000000..ae88236 --- /dev/null +++ b/models/profile.js @@ -0,0 +1,24 @@ +'use strict'; +module.exports = function(sequelize, DataTypes) { + var Profile = sequelize.define('Profile', { + userId: DataTypes.INTEGER, + fname: DataTypes.STRING, + lname: DataTypes.STRING, + 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 + }, { + classMethods: { + associate: function(models) { + // associations can be defined here + } + } + }); + return Profile; +}; \ No newline at end of file diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..b472097 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,49 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/home/alex/.nvm/versions/node/v6.0.0/bin/node', +1 verbose cli '/home/alex/.nvm/versions/node/v6.0.0/bin/npm', +1 verbose cli 'run', +1 verbose cli 'seed' ] +2 info using npm@3.8.6 +3 info using node@v6.0.0 +4 verbose run-script [ 'preseed', 'seed', 'postseed' ] +5 info lifecycle assignment_okodin@1.0.0~preseed: assignment_okodin@1.0.0 +6 silly lifecycle assignment_okodin@1.0.0~preseed: no script for preseed, continuing +7 info lifecycle assignment_okodin@1.0.0~seed: assignment_okodin@1.0.0 +8 verbose lifecycle assignment_okodin@1.0.0~seed: unsafe-perm in lifecycle true +9 verbose lifecycle assignment_okodin@1.0.0~seed: PATH: /home/alex/.nvm/versions/node/v6.0.0/lib/node_modules/npm/bin/node-gyp-bin:/home/alex/vcs/assignments_course/Databases/assignment_okodin/node_modules/.bin:/home/alex/.nvm/versions/node/v6.0.0/bin:/home/alex/bin:/home/alex/.nvm/versions/node/v6.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin +10 verbose lifecycle assignment_okodin@1.0.0~seed: CWD: /home/alex/vcs/assignments_course/Databases/assignment_okodin +11 silly lifecycle assignment_okodin@1.0.0~seed: Args: [ '-c', +11 silly lifecycle 'sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all' ] +12 silly lifecycle assignment_okodin@1.0.0~seed: Returned: code: 1 signal: null +13 info lifecycle assignment_okodin@1.0.0~seed: Failed to exec seed script +14 verbose stack Error: assignment_okodin@1.0.0 seed: `sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all` +14 verbose stack Exit status 1 +14 verbose stack at EventEmitter. (/home/alex/.nvm/versions/node/v6.0.0/lib/node_modules/npm/lib/utils/lifecycle.js:239:16) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at EventEmitter.emit (events.js:191:7) +14 verbose stack at ChildProcess. (/home/alex/.nvm/versions/node/v6.0.0/lib/node_modules/npm/lib/utils/spawn.js:24:14) +14 verbose stack at emitTwo (events.js:106:13) +14 verbose stack at ChildProcess.emit (events.js:191:7) +14 verbose stack at maybeClose (internal/child_process.js:850:16) +14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) +15 verbose pkgid assignment_okodin@1.0.0 +16 verbose cwd /home/alex/vcs/assignments_course/Databases/assignment_okodin +17 error Linux 4.10.0-30-generic +18 error argv "/home/alex/.nvm/versions/node/v6.0.0/bin/node" "/home/alex/.nvm/versions/node/v6.0.0/bin/npm" "run" "seed" +19 error node v6.0.0 +20 error npm v3.8.6 +21 error code ELIFECYCLE +22 error assignment_okodin@1.0.0 seed: `sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all` +22 error Exit status 1 +23 error Failed at the assignment_okodin@1.0.0 seed script 'sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all'. +23 error Make sure you have the latest version of node.js and npm installed. +23 error If you do, this is most likely a problem with the assignment_okodin package, +23 error not with npm itself. +23 error Tell the author that this fails on your system: +23 error sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all +23 error You can get information on how to open an issue for this project with: +23 error npm bugs assignment_okodin +23 error Or if that isn't available, you can get their info via: +23 error npm owner ls assignment_okodin +23 error There is likely additional logging output above. +24 verbose exit [ 1, true ] diff --git a/package.json b/package.json index f9d4bb0..ee0c419 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,14 @@ "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" + "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", @@ -21,6 +28,7 @@ "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", diff --git a/seeders/20170807172759-User.js b/seeders/20170807172759-User.js new file mode 100644 index 0000000..e979fb9 --- /dev/null +++ b/seeders/20170807172759-User.js @@ -0,0 +1,38 @@ +'use strict'; + +let models = require("./../models"); +console.log(Object.keys(models)); + +module.exports = { + up: function (queryInterface, Sequelize) { + /* + Add altering commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkInsert('Person', [{ + name: 'John Doe', + isBetaMember: false + }], {}); + */ + var users = []; + for (let i = 0; i < 3; i++) { + users.push({ + username: `foobar${i}`, + email: `foobar${i}@gmail.com`, + profileId: i}); + } + return queryInterface.bulkInsert('User', users); + }, + + down: function (queryInterface, Sequelize) { + /* + Add reverting commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkDelete('Person', null, {}); + */ + return queryInterface.bulkDelete('User', null, {}, models.User); + } +}; diff --git a/seeders/20170807172806-Profile.js b/seeders/20170807172806-Profile.js new file mode 100644 index 0000000..f8e2762 --- /dev/null +++ b/seeders/20170807172806-Profile.js @@ -0,0 +1,47 @@ +'use strict'; + +let models = require("./../models"); + +module.exports = { + up: function(queryInterface, Sequelize) { + /* + Add altering commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkInsert('Person', [{ + name: 'John Doe', + isBetaMember: false + }], {}); + */ + + var profiles = []; + for (let i = 0; i < 3; i++) { + profiles.push({ + fname: `Name${i}`, + lname: `Name${i}`, + age: i + 30, + city: `City of HomeDepot${i}`, + distance: i + 4, + mstatus: "single", + height: i + 30, + children: i, + occupation: "Vikings", + education: "Viking Code School", + userId: i + }); + } + return queryInterface.bulkInsert('Profile', profiles); + }, + + down: function(queryInterface, Sequelize) { + /* + Add reverting commands here. + Return a promise to correctly handle asynchronicity. + + Example: + return queryInterface.bulkDelete('Person', null, {}); + */ + return queryInterface.bulkDelete('Profile', null, {}, models.Profile); + } +}; From 4c147e12d1229eded3c41c0e98c74a14f572f2ee Mon Sep 17 00:00:00 2001 From: Greg Filipczak Date: Mon, 7 Aug 2017 17:58:45 +0000 Subject: [PATCH 3/8] seeds --- .gitignore | 2 + config/config.json | 2 +- migrations/20170804031918-create-user.js | 35 +++++++++++++++ migrations/20170807171419-create-profile.js | 10 ++--- npm-debug.log | 49 --------------------- repl.js | 32 ++++++++++++++ 6 files changed, 75 insertions(+), 55 deletions(-) create mode 100644 migrations/20170804031918-create-user.js delete mode 100644 npm-debug.log create mode 100644 repl.js diff --git a/.gitignore b/.gitignore index 08b2553..f78416b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules + +config/ diff --git a/config/config.json b/config/config.json index 9a23407..7f610ce 100644 --- a/config/config.json +++ b/config/config.json @@ -1,7 +1,7 @@ { "development": { "username": "postgres", - "password": "password", + "password": "postgres", "database": "database_development", "host": "127.0.0.1", "dialect": "postgres" diff --git a/migrations/20170804031918-create-user.js b/migrations/20170804031918-create-user.js new file mode 100644 index 0000000..8acb8d5 --- /dev/null +++ b/migrations/20170804031918-create-user.js @@ -0,0 +1,35 @@ +"use strict"; +module.exports = { + up: function(queryInterface, Sequelize) { + return queryInterface.createTable("User", { + id: { + allowNull: false, + autoIncrement: true, + primaryKey: true, + type: Sequelize.INTEGER + }, + username: { + type: Sequelize.STRING + }, + email: { + type: Sequelize.STRING + }, + profileId: { + 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("User"); + } +}; diff --git a/migrations/20170807171419-create-profile.js b/migrations/20170807171419-create-profile.js index c9a7731..709c859 100644 --- a/migrations/20170807171419-create-profile.js +++ b/migrations/20170807171419-create-profile.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; module.exports = { up: function(queryInterface, Sequelize) { - return queryInterface.createTable('Profiles', { + return queryInterface.createTable("Profile", { id: { allowNull: false, autoIncrement: true, @@ -47,16 +47,16 @@ module.exports = { createdAt: { allowNull: false, type: Sequelize.DATE, - defaultValue: Sequelize.fn('NOW') + defaultValue: Sequelize.fn("NOW") }, updatedAt: { allowNull: false, type: Sequelize.DATE, - defaultValue: Sequelize.fn('NOW') + defaultValue: Sequelize.fn("NOW") } }); }, down: function(queryInterface, Sequelize) { - return queryInterface.dropTable('Profiles'); + return queryInterface.dropTable("Profile"); } }; diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index b472097..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,49 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/home/alex/.nvm/versions/node/v6.0.0/bin/node', -1 verbose cli '/home/alex/.nvm/versions/node/v6.0.0/bin/npm', -1 verbose cli 'run', -1 verbose cli 'seed' ] -2 info using npm@3.8.6 -3 info using node@v6.0.0 -4 verbose run-script [ 'preseed', 'seed', 'postseed' ] -5 info lifecycle assignment_okodin@1.0.0~preseed: assignment_okodin@1.0.0 -6 silly lifecycle assignment_okodin@1.0.0~preseed: no script for preseed, continuing -7 info lifecycle assignment_okodin@1.0.0~seed: assignment_okodin@1.0.0 -8 verbose lifecycle assignment_okodin@1.0.0~seed: unsafe-perm in lifecycle true -9 verbose lifecycle assignment_okodin@1.0.0~seed: PATH: /home/alex/.nvm/versions/node/v6.0.0/lib/node_modules/npm/bin/node-gyp-bin:/home/alex/vcs/assignments_course/Databases/assignment_okodin/node_modules/.bin:/home/alex/.nvm/versions/node/v6.0.0/bin:/home/alex/bin:/home/alex/.nvm/versions/node/v6.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin -10 verbose lifecycle assignment_okodin@1.0.0~seed: CWD: /home/alex/vcs/assignments_course/Databases/assignment_okodin -11 silly lifecycle assignment_okodin@1.0.0~seed: Args: [ '-c', -11 silly lifecycle 'sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all' ] -12 silly lifecycle assignment_okodin@1.0.0~seed: Returned: code: 1 signal: null -13 info lifecycle assignment_okodin@1.0.0~seed: Failed to exec seed script -14 verbose stack Error: assignment_okodin@1.0.0 seed: `sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all` -14 verbose stack Exit status 1 -14 verbose stack at EventEmitter. (/home/alex/.nvm/versions/node/v6.0.0/lib/node_modules/npm/lib/utils/lifecycle.js:239:16) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at EventEmitter.emit (events.js:191:7) -14 verbose stack at ChildProcess. (/home/alex/.nvm/versions/node/v6.0.0/lib/node_modules/npm/lib/utils/spawn.js:24:14) -14 verbose stack at emitTwo (events.js:106:13) -14 verbose stack at ChildProcess.emit (events.js:191:7) -14 verbose stack at maybeClose (internal/child_process.js:850:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5) -15 verbose pkgid assignment_okodin@1.0.0 -16 verbose cwd /home/alex/vcs/assignments_course/Databases/assignment_okodin -17 error Linux 4.10.0-30-generic -18 error argv "/home/alex/.nvm/versions/node/v6.0.0/bin/node" "/home/alex/.nvm/versions/node/v6.0.0/bin/npm" "run" "seed" -19 error node v6.0.0 -20 error npm v3.8.6 -21 error code ELIFECYCLE -22 error assignment_okodin@1.0.0 seed: `sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all` -22 error Exit status 1 -23 error Failed at the assignment_okodin@1.0.0 seed script 'sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the assignment_okodin package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all -23 error You can get information on how to open an issue for this project with: -23 error npm bugs assignment_okodin -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls assignment_okodin -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/repl.js b/repl.js new file mode 100644 index 0000000..f3541e6 --- /dev/null +++ b/repl.js @@ -0,0 +1,32 @@ +// Require the REPL module +// and models +var repl = require("repl").start({}); +var models = require("./models"); + +// Make the `models` object +// a global variable in the +// REPL +repl.context.models = models; + +// Make each model a global +// object in the REPL +Object.keys(models).forEach(modelName => { + repl.context[modelName] = models[modelName]; +}); + +// Provide a convenience function `lg` +// to pass to `then()` and `catch()` +// to output less verbose values for +// sequelize model query results +repl.context.lg = data => { + if (Array.isArray(data)) { + if (data.length && data[0].dataValues) { + data = data.map(item => item.dataValues); + } + } else { + if (data.dataValues) { + data = data.dataValues; + } + } + console.log(data); +}; From 6169c31ce584b11a1d5148dcf702b66c37e3ba02 Mon Sep 17 00:00:00 2001 From: Alex-Willenbrink Date: Mon, 7 Aug 2017 14:55:06 -0500 Subject: [PATCH 4/8] added home page --- app.js | 14 ++++++++++- config/config.json | 2 +- migrations/20170804031918-create-user.js | 4 +-- migrations/20170807171419-create-profile.js | 4 +-- seeders/20170807172759-User.js | 9 ++++--- seeders/20170807172806-Profile.js | 6 ++--- views/home.handlebars | 28 +++++++++++++++++++++ views/layouts/main.handlebars | 17 +++++++++++++ views/login.handlebars | 12 +++++++++ 9 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 views/home.handlebars create mode 100644 views/layouts/main.handlebars create mode 100644 views/login.handlebars diff --git a/app.js b/app.js index 6c5c6f5..c5bdd93 100644 --- a/app.js +++ b/app.js @@ -17,10 +17,22 @@ app.use(session( // name: 'session' // })) const exhbs = require("express-handlebars"); -const hbs = exbhs.create({ defaultLayout: "main" }); +const hbs = exhbs.create({ defaultLayout: "main" }); app.engine("handlebars", hbs.engine); app.set("view engine", "handlebars"); +let sess; + +app.get("/", (req, res) => { + res.render("home"); +}) + +app.post("/login", (req, res) => { + sess = req.session; + sess.username = req.body.username; + + res.redirect("/profile") +}) app.listen(3000, () => { diff --git a/config/config.json b/config/config.json index 7f610ce..9a23407 100644 --- a/config/config.json +++ b/config/config.json @@ -1,7 +1,7 @@ { "development": { "username": "postgres", - "password": "postgres", + "password": "password", "database": "database_development", "host": "127.0.0.1", "dialect": "postgres" diff --git a/migrations/20170804031918-create-user.js b/migrations/20170804031918-create-user.js index 8acb8d5..d3f77f7 100644 --- a/migrations/20170804031918-create-user.js +++ b/migrations/20170804031918-create-user.js @@ -1,7 +1,7 @@ "use strict"; module.exports = { up: function(queryInterface, Sequelize) { - return queryInterface.createTable("User", { + return queryInterface.createTable("Users", { id: { allowNull: false, autoIncrement: true, @@ -30,6 +30,6 @@ module.exports = { }); }, down: function(queryInterface, Sequelize) { - return queryInterface.dropTable("User"); + return queryInterface.dropTable("Users"); } }; diff --git a/migrations/20170807171419-create-profile.js b/migrations/20170807171419-create-profile.js index 709c859..b4d4d75 100644 --- a/migrations/20170807171419-create-profile.js +++ b/migrations/20170807171419-create-profile.js @@ -1,7 +1,7 @@ "use strict"; module.exports = { up: function(queryInterface, Sequelize) { - return queryInterface.createTable("Profile", { + return queryInterface.createTable("Profiles", { id: { allowNull: false, autoIncrement: true, @@ -57,6 +57,6 @@ module.exports = { }); }, down: function(queryInterface, Sequelize) { - return queryInterface.dropTable("Profile"); + return queryInterface.dropTable("Profiles"); } }; diff --git a/seeders/20170807172759-User.js b/seeders/20170807172759-User.js index e979fb9..d1bdf9e 100644 --- a/seeders/20170807172759-User.js +++ b/seeders/20170807172759-User.js @@ -1,7 +1,7 @@ 'use strict'; let models = require("./../models"); -console.log(Object.keys(models)); +// console.log(Object.keys(models)); module.exports = { up: function (queryInterface, Sequelize) { @@ -20,9 +20,10 @@ module.exports = { users.push({ username: `foobar${i}`, email: `foobar${i}@gmail.com`, - profileId: i}); + profileId: i + 1 + }); } - return queryInterface.bulkInsert('User', users); + return queryInterface.bulkInsert('Users', users); }, down: function (queryInterface, Sequelize) { @@ -33,6 +34,6 @@ module.exports = { Example: return queryInterface.bulkDelete('Person', null, {}); */ - return queryInterface.bulkDelete('User', null, {}, models.User); + return queryInterface.bulkDelete('Users', null, {}, models.User); } }; diff --git a/seeders/20170807172806-Profile.js b/seeders/20170807172806-Profile.js index f8e2762..b7ba86a 100644 --- a/seeders/20170807172806-Profile.js +++ b/seeders/20170807172806-Profile.js @@ -28,10 +28,10 @@ module.exports = { children: i, occupation: "Vikings", education: "Viking Code School", - userId: i + userId: i + 1 }); } - return queryInterface.bulkInsert('Profile', profiles); + return queryInterface.bulkInsert('Profiles', profiles); }, down: function(queryInterface, Sequelize) { @@ -42,6 +42,6 @@ module.exports = { Example: return queryInterface.bulkDelete('Person', null, {}); */ - return queryInterface.bulkDelete('Profile', null, {}, models.Profile); + return queryInterface.bulkDelete('Profiles', null, {}, models.Profile); } }; diff --git a/views/home.handlebars b/views/home.handlebars new file mode 100644 index 0000000..c65b36d --- /dev/null +++ b/views/home.handlebars @@ -0,0 +1,28 @@ + + +
+
+

Please Log In Sir or Ma'am

+
+
+ + +
+ +
+
+
+ + +
+
+

Please Sign Up

+
+
+ + +
+ +
+
+
diff --git a/views/layouts/main.handlebars b/views/layouts/main.handlebars new file mode 100644 index 0000000..a76831f --- /dev/null +++ b/views/layouts/main.handlebars @@ -0,0 +1,17 @@ + + + + + + + + + + + +
+ {{{ body }}} +
+ + + diff --git a/views/login.handlebars b/views/login.handlebars new file mode 100644 index 0000000..f6d23a2 --- /dev/null +++ b/views/login.handlebars @@ -0,0 +1,12 @@ +
+
+

Please Log In

+
+
+ + +
+ +
+
+
From 3a7a588a32f35f35f54ca56e031e82a9f6331a2b Mon Sep 17 00:00:00 2001 From: Greg Filipczak Date: Mon, 7 Aug 2017 20:23:23 +0000 Subject: [PATCH 5/8] working on views --- app.js | 44 ++++++++++++++----- views/home.handlebars | 6 ++- views/profileForm.handlebars | 85 ++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 11 deletions(-) create mode 100644 views/profileForm.handlebars diff --git a/app.js b/app.js index c5bdd93..8fa553e 100644 --- a/app.js +++ b/app.js @@ -5,12 +5,13 @@ 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 -})); +app.use( + session({ + secret: "12345", + resave: false, + saveUninitialized: true + }) +); // const session = require("cookie-session"); // app.use(session({ @@ -25,16 +26,39 @@ let sess; app.get("/", (req, res) => { res.render("home"); -}) +}); app.post("/login", (req, res) => { sess = req.session; sess.username = req.body.username; - res.redirect("/profile") -}) + res.redirect("/profile"); +}); +// app.post('/profile', (req, res)=> { +// sess = req.session; +// sess.username = req.body.username; +// +// +// }) + +app.post("/newprofile", (req, res) => { + sess = req.session; + sess.username = req.body.username; + sess.email = req.body.email; + res.render("profileForm"); +}); + +app.post("/profileCreate", (req, res) => { + sess = req.session; + sess.username = req.body.username; + sess.email = req.body.email; + console.log(sess.email); + console.log(sess.username); + console.log(req.body); + res.end("test"); +}); app.listen(3000, () => { console.log("I'm listening"); -}) +}); diff --git a/views/home.handlebars b/views/home.handlebars index c65b36d..47463de 100644 --- a/views/home.handlebars +++ b/views/home.handlebars @@ -18,9 +18,13 @@

Please Sign Up

+
+ + +
- +
diff --git a/views/profileForm.handlebars b/views/profileForm.handlebars new file mode 100644 index 0000000..6faa39d --- /dev/null +++ b/views/profileForm.handlebars @@ -0,0 +1,85 @@ +
+
+

Please Sign Up

+ +
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+
+
From 9aedcaa7b54203f00c908c4f5c14c742cd92be83 Mon Sep 17 00:00:00 2001 From: Alex-Willenbrink Date: Mon, 7 Aug 2017 16:07:17 -0500 Subject: [PATCH 6/8] join should be working, redid entire migration --- app.js | 36 +------- migrations/20170804031918-create-user.js | 35 -------- ...-user.js => 20170807205857-create-user.js} | 11 +-- models/profile.js | 19 ++-- models/user.js | 3 +- routes/index.js | 86 +++++++++++++++++++ seeders/20170807172759-User.js | 3 +- views/profileForm.handlebars | 4 +- 8 files changed, 107 insertions(+), 90 deletions(-) delete mode 100644 migrations/20170804031918-create-user.js rename migrations/{20170807170646-create-user.js => 20170807205857-create-user.js} (81%) create mode 100644 routes/index.js diff --git a/app.js b/app.js index 8fa553e..267f214 100644 --- a/app.js +++ b/app.js @@ -22,42 +22,10 @@ const hbs = exhbs.create({ defaultLayout: "main" }); app.engine("handlebars", hbs.engine); app.set("view engine", "handlebars"); -let sess; +const vikingRoutes = require("./routes"); +app.use('/', vikingRoutes); -app.get("/", (req, res) => { - res.render("home"); -}); - -app.post("/login", (req, res) => { - sess = req.session; - sess.username = req.body.username; - - res.redirect("/profile"); -}); -// app.post('/profile', (req, res)=> { -// sess = req.session; -// sess.username = req.body.username; -// -// -// }) - -app.post("/newprofile", (req, res) => { - sess = req.session; - sess.username = req.body.username; - sess.email = req.body.email; - res.render("profileForm"); -}); - -app.post("/profileCreate", (req, res) => { - sess = req.session; - sess.username = req.body.username; - sess.email = req.body.email; - console.log(sess.email); - console.log(sess.username); - console.log(req.body); - res.end("test"); -}); app.listen(3000, () => { console.log("I'm listening"); diff --git a/migrations/20170804031918-create-user.js b/migrations/20170804031918-create-user.js deleted file mode 100644 index d3f77f7..0000000 --- a/migrations/20170804031918-create-user.js +++ /dev/null @@ -1,35 +0,0 @@ -"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 - }, - email: { - type: Sequelize.STRING - }, - profileId: { - 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"); - } -}; diff --git a/migrations/20170807170646-create-user.js b/migrations/20170807205857-create-user.js similarity index 81% rename from migrations/20170807170646-create-user.js rename to migrations/20170807205857-create-user.js index cbf3203..e632617 100644 --- a/migrations/20170807170646-create-user.js +++ b/migrations/20170807205857-create-user.js @@ -8,24 +8,21 @@ module.exports = { primaryKey: true, type: Sequelize.INTEGER }, - username: { - type: Sequelize.STRING - }, email: { type: Sequelize.STRING }, - profileId: { - type: Sequelize.INTEGER + username: { + type: Sequelize.STRING }, createdAt: { allowNull: false, type: Sequelize.DATE, - defaultValue: Sequelize.fn('NOW') + defaultValue: Sequelize.fn("NOW") }, updatedAt: { allowNull: false, type: Sequelize.DATE, - defaultValue: Sequelize.fn('NOW') + defaultValue: Sequelize.fn("NOW") } }); }, diff --git a/models/profile.js b/models/profile.js index ae88236..9b0d52f 100644 --- a/models/profile.js +++ b/models/profile.js @@ -1,4 +1,7 @@ 'use strict'; + +const models = require("../models"); + module.exports = function(sequelize, DataTypes) { var Profile = sequelize.define('Profile', { userId: DataTypes.INTEGER, @@ -13,12 +16,12 @@ module.exports = function(sequelize, DataTypes) { children: DataTypes.INTEGER, occupation: DataTypes.STRING, education: DataTypes.STRING - }, { - classMethods: { - associate: function(models) { - // associations can be defined here - } - } - }); + }) + + Profile.associate = function(models) { + Profile.belongsTo(models.User, { + foreignKey: userId + }; + } return Profile; -}; \ No newline at end of file +}; diff --git a/models/user.js b/models/user.js index b45d53d..89d55a8 100644 --- a/models/user.js +++ b/models/user.js @@ -1,9 +1,8 @@ 'use strict'; module.exports = function(sequelize, DataTypes) { var User = sequelize.define('User', { - username: DataTypes.STRING, email: DataTypes.STRING, - profileId: DataTypes.INTEGER + username: DataTypes.STRING }, { classMethods: { associate: function(models) { diff --git a/routes/index.js b/routes/index.js new file mode 100644 index 0000000..d52b3f6 --- /dev/null +++ b/routes/index.js @@ -0,0 +1,86 @@ +const express = require("express"); +const router = express.Router(); +const models = require("./../models"); + +let { + User, + Profile +} = models; +const sequelize = models.sequelize; + +let sess; + +router.get("/", (req, res) => { + res.render("home"); +}); + +router.post("/login", (req, res) => { + sess = req.session; + sess.username = req.body.username; + + res.redirect("/profile"); +}); + +// app.post('/profile', (req, res)=> { +// sess = req.session; +// sess.username = req.body.username; +// +// +// }) + +router.post("/newprofile", (req, res) => { + sess = req.session; + sess.username = req.body.username; + sess.email = req.body.email; + res.render("profileForm"); +}); + +router.post("/profileCreate", (req, res) => { + sess = req.session; + sess.username = req.body.username; + sess.email = req.body.email; + + let username; + let email; + let fname; + let lname; + let gender; + let city; + let age; + let distance; + let occupation; + let education; + let children; + let mStatus; + + let userParams = { + username: sess.username, + email: sess.email + } + + profile = req.body.profiles; + let profileParams = { + fname: profiles.fname, + lname: profiles.lname, + gender: profiles.gender, + city: profiles.city, + age: profiles.age, + distance: profiles.distance, + occupation: profiles.occupation, + education: profiles.education, + children: profiles.children, + mstatus: profiles.mstatus + } + + sequelize.transacction((t) => { + + }) + + + console.log(sess.email); + console.log(sess.username); + console.log(req.body); + res.end("test"); +}); + +module.exports = router; diff --git a/seeders/20170807172759-User.js b/seeders/20170807172759-User.js index d1bdf9e..b861e53 100644 --- a/seeders/20170807172759-User.js +++ b/seeders/20170807172759-User.js @@ -19,8 +19,7 @@ module.exports = { for (let i = 0; i < 3; i++) { users.push({ username: `foobar${i}`, - email: `foobar${i}@gmail.com`, - profileId: i + 1 + email: `foobar${i}@gmail.com` }); } return queryInterface.bulkInsert('Users', users); diff --git a/views/profileForm.handlebars b/views/profileForm.handlebars index 6faa39d..97759b2 100644 --- a/views/profileForm.handlebars +++ b/views/profileForm.handlebars @@ -32,7 +32,7 @@
- @@ -71,7 +71,7 @@
- +