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

drewdiddy611's Solution' #10

Open
wants to merge 11 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
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
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?

Andrew and Will
55 changes: 55 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const express = require('express');
const app = express();

// Templates
const expressHandlebars = require('express-handlebars');
const hbs = expressHandlebars.create({
partialsDir: 'views/',
defaultLayout: 'application'
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');

// Post Data
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));

// Log Request Info
const morgan = require('morgan');
const morganToolkit = require('morgan-toolkit')(morgan);
app.use(morganToolkit());

// Method Overriding
const methodOverride = require('method-override');
const getPostSupport = require('express-method-override-get-post-support');
app.use(methodOverride(getPostSupport.callback, getPostSupport.options));

app.get('/', (req, res) => {
res.redirect('/users');
});

// Redirect Sugar
express.response.doRedirect = function(path) {
let _this = this;
return function() {
_this.redirect(path);
};
};

// Routes
app.use('/users', require('./routers/users'));
app.use('/calendars', require('./routers/calendars'));
app.use('/events', require('./routers/events'));

// Set up port/host
const port = process.env.PORT || process.argv[2] || 3000;
const host = 'localhost';
let args = process.env.NODE_ENV === 'production' ? [port] : [port, host];

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

// Use apply to pass the args to listen
app.listen.apply(app, args);
76 changes: 76 additions & 0 deletions app.js.back
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const express = require('express');
const app = express();

const Model = require('sequelize').Model;

// Templates
const expressHandlebars = require('express-handlebars');
const hbs = expressHandlebars.create({
partialsDir: 'views/',
defaultLayout: 'application'
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');

// Post Data
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));

// Log Request Info
const morgan = require('morgan');
const morganToolkit = require('morgan-toolkit')(morgan);
app.use(morganToolkit());

// Method Overriding
const methodOverride = require('method-override');
const getPostSupport = require('express-method-override-get-post-support');
app.use(methodOverride(getPostSupport.callback, getPostSupport.options));

app.get('/', (req, res) => {
res.redirect('/users');
});

// Redirect Sugar
express.response.doRedirect = function(location) {
let _this = this;

if (typeof location === 'object') {
let path;
if (location instanceof Model) {
// Get the model name in plural format and lowercase it.
path =
'/' +
location._modelOptions.name.plural.toLowerCase() +
'/' +
location.get('id');
} else {
path = '/';
}
//_this.redirect(path);
} else if (typeof location === 'string') {
return function() {
console.log(_this);
_this.redirect(location);
};
}
};

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

const calendarRoutes = require('./routers/calendars');
app.use('/calendars', calendarRoutes);

// Set up port/host
const port = process.env.PORT || process.argv[2] || 3000;
const host = 'localhost';
let args = process.env.NODE_ENV === 'production' ? [port] : [port, host];

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

// Use apply to pass the args to listen
app.listen.apply(app, args);
38 changes: 38 additions & 0 deletions migrations/20170804022821-create-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("Users", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
fname: {
type: Sequelize.STRING
},
lname: {
type: Sequelize.STRING
},
username: {
type: Sequelize.STRING
},
email: {
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/20170804155738-create-calendar.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('Calendars', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
userId: {
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('Calendars');
}
};
23 changes: 23 additions & 0 deletions migrations/20170804164608-User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = {
up: function (queryInterface, Sequelize) {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},

down: function (queryInterface, Sequelize) {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.dropTable('users');
*/
}
};
23 changes: 23 additions & 0 deletions migrations/20170804164619-Calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = {
up: function (queryInterface, Sequelize) {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},

down: function (queryInterface, Sequelize) {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.dropTable('users');
*/
}
};
23 changes: 23 additions & 0 deletions migrations/20170804164819-Calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

module.exports = {
up: function (queryInterface, Sequelize) {
/*
Add altering commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.createTable('users', { id: Sequelize.INTEGER });
*/
},

down: function (queryInterface, Sequelize) {
/*
Add reverting commands here.
Return a promise to correctly handle asynchronicity.

Example:
return queryInterface.dropTable('users');
*/
}
};
42 changes: 42 additions & 0 deletions migrations/20170804195732-create-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";

module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable("CalendarEvents", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
description: {
type: Sequelize.TEXT
},
startDateTime: {
type: Sequelize.BIGINT
},
endDateTime: {
type: Sequelize.BIGINT
},
calendarId: {
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("CreateEvents");
}
};
18 changes: 18 additions & 0 deletions models/calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var Calendar = sequelize.define('Calendar', {
name: DataTypes.STRING,
userId: DataTypes.INTEGER
});

Calendar.associate = function(models) {
Calendar.belongsTo(models.User, {
foreignKey: 'userId'
});
Calendar.hasMany(models.CalendarEvent, {
foreignKey: 'calendarId'
});
};

return Calendar;
};
17 changes: 17 additions & 0 deletions models/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
module.exports = function(sequelize, DataTypes) {
var CalendarEvent = sequelize.define("CalendarEvent", {
name: DataTypes.STRING,
description: DataTypes.TEXT,
startDateTime: DataTypes.BIGINT,
endDateTime: DataTypes.BIGINT,
calendarId: DataTypes.INTEGER
});

CalendarEvent.associate = function(models) {
CalendarEvent.belongsTo(models.Calendar, {
foreignKey: "calendarId"
});
};
return CalendarEvent;
};
Loading