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

EdTriplett's Solution' #14

Open
wants to merge 7 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
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
migrations/
seeders/
models/
config/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# assignment_calendar_event_planner
I'll pencil you in on Tuesday around noonish?

Daniel and Ed
101 changes: 101 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var express = require('express');
var app = express();


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


// ----------------------------------------
// 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'] }
));


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


// ----------------------------------------
// Logging
// ----------------------------------------
var morgan = require('morgan');
app.use(morgan('tiny'));
app.use((req, res, next) => {
['query', 'params', 'body'].forEach((key) => {
if (req[key]) {
var capKey = key[0].toUpperCase() + key.substr(1);
var value = JSON.stringify(req[key], null, 2);
console.log(`${ capKey }: ${ value }`);
}
});
next();
});


// ----------------------------------------
// Routes
// ----------------------------------------
var usersRoutes = require('./routers/users');
app.use('/', usersRoutes);


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

var hbs = expressHandlebars.create({
partialsDir: 'views/',
defaultLayout: 'application'
});

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


// ----------------------------------------
// 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;










23 changes: 23 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"development": {
"username": "anapaulac",
"password": null,
"database": "calander_event_planner_development",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "anapaulac",
"password": null,
"database": "calander_event_planner_test",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"username": "root",
"password": null,
"database": "database_production",
"host": "127.0.0.1",
"dialect": "postgres"
}
}
18 changes: 18 additions & 0 deletions models/calEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var calEvent = sequelize.define('calEvent', {
name: DataTypes.STRING,
description: DataTypes.STRING,
date: DataTypes.STRING,
start: DataTypes.STRING,
end: DataTypes.STRING,
calendarId: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return calEvent;
};
16 changes: 16 additions & 0 deletions models/calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

module.exports = function(sequelize, DataTypes) {
var Calendar = sequelize.define('Calendar', {
name: DataTypes.STRING,
userId: DataTypes.STRING

}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return Calendar;
};
49 changes: 49 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'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;













15 changes: 15 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
fname: DataTypes.STRING,
lname: DataTypes.STRING,
username: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return User;
};
28 changes: 28 additions & 0 deletions npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'sequelize',
1 verbose cli 'db:seed:all' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: missing script: sequelize
4 verbose stack at run (C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:151:19)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\lib\run-script.js:61:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:356:5
4 verbose stack at checkBinReferences_ (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:320:45)
4 verbose stack at final (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:354:3)
4 verbose stack at then (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:124:5)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:311:12
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16
4 verbose stack at tryToString (fs.js:456:3)
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:443:12)
5 verbose cwd C:\VikingStuff\PairProgramming\day15_calendareventPlanner_sequelize\assignment_calendar_event_planner
6 error Windows_NT 10.0.15063
7 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "sequelize" "db:seed:all"
8 error node v6.11.0
9 error npm v3.10.10
10 error missing script: sequelize
11 error If you need help, you may report this error at:
11 error <https://github.com/npm/npm/issues>
12 verbose exit [ 1, true ]
Loading