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

finish project #4

Open
wants to merge 9 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node app.js
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# assignment_calendar_event_planner
I'll pencil you in on Tuesday around noonish?
# Calendar Event Planner

## Introduction
This is a simple calendar event planner that runs on PostgreSQL.

## Technologies Used
PostgreSQL, Node, Express

## Getting Started
Clone the repository and install dependencies. Create a Postgres database on your local machine titled `assignment_calendar_event_planner_development`. Populate the database with mock data using `npm run seed`. Run the file with `node app.js`.

## Deployment Link
A deployed version of this project may be found [here.](https://gentle-depths-89101.herokuapp.com/users)

Try creating different resources like events, users, and invitations. You can also view individual resources by clicking on them.
95 changes: 95 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const express = require('express');
const app = express();

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


// ----------------------------------------
// Method Override
// ----------------------------------------
app.use((req, res, next) => {
let method;
if (req.query._method) {
method = req.query._method;
delete req.query._method;
} else if (typeof req.body === 'object' && req.body._method) {
method = req.body._method;
delete req.body._method;
}

if (method) {
method = method.toUpperCase();
req.method = method;
}

next();
});

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

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

// ----------------------------------------
// Routes
// ----------------------------------------
const users = require('./routers/users');
const calendars = require('./routers/calendars');
const events = require('./routers/events');
const invitations = require('./routers/invitations');
app.get('/', (req, res) => { res.redirect('/users'); });
app.use('/users', users);
app.use('/calendars', calendars);
app.use('/events', events);
app.use('/invitations', invitations);

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

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

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

// ----------------------------------------
// Server
// ----------------------------------------
const port = process.env.PORT ||
process.argv[2] ||
4000;
const host = 'localhost';

let 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.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const config = {
"development": {
"username": process.env.POSTGRES_USERNAME,
"password": process.env.POSTGRES_PASSWORD,
"database": "assignment_calendar_event_planner_development",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "christian",
"password": null,
"database": "assignment_calendar_event_planner_test",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"use_env_variable": "DATABASE_URL",
"dialect": "postgres"
}
};


module.exports = config;
31 changes: 31 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const gulp = require('gulp');
const browserSync = require('browser-sync');
const nodemon = require('gulp-nodemon');

gulp.task('default', ['browser-sync', 'nodemon'], () => {});

gulp.task('browser-sync', () => {
browserSync.init(null, {
proxy: "localhost:4000", //this should be whatever your app is set to listen on
browser: "google-chrome",
port: 7001
});
gulp.watch('./views/**/*.handlebars').on('change', browserSync.reload);
gulp.watch('./public/**/*.*').on('change', browserSync.reload);
});

gulp.task('nodemon', (callback) => {
var started = false;

return nodemon({
script: 'app.js' // this is where you app is located
})
.on('start', () =>{
if (!started) {
callback();
started = true;
}
});
});
38 changes: 38 additions & 0 deletions migrations/20170605153843-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/20170605233331-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');
}
};
44 changes: 44 additions & 0 deletions migrations/20170606015925-create-event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.createTable('Events', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING
},
description: {
type: Sequelize.TEXT
},
date: {
type: Sequelize.DATEONLY
},
start: {
type: Sequelize.TIME
},
end: {
type: Sequelize.TIME
},
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('Events');
}
};
32 changes: 32 additions & 0 deletions migrations/20170606045922-create-invitation.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('Invitations', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
eventId: {
type: Sequelize.INTEGER
},
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('Invitations');
}
};
14 changes: 14 additions & 0 deletions models/calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var Calendar = sequelize.define('Calendar', {
name: DataTypes.STRING,
userId: DataTypes.INTEGER
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return Calendar;
};
18 changes: 18 additions & 0 deletions models/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
module.exports = function(sequelize, DataTypes) {
var Event = sequelize.define('Event', {
name: DataTypes.STRING,
description: DataTypes.TEXT,
date: DataTypes.DATEONLY,
start: DataTypes.TIME,
end: DataTypes.TIME,
calendarId: DataTypes.INTEGER
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return Event;
};
Loading