Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
Ran prettier on repo
Browse files Browse the repository at this point in the history
  • Loading branch information
philbarresi committed Mar 3, 2018
1 parent 173a1c6 commit a6a359e
Show file tree
Hide file tree
Showing 80 changed files with 21,555 additions and 16,962 deletions.
72 changes: 36 additions & 36 deletions Labs/lab_7/app.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const static = express.static(__dirname + '/public');

const configRoutes = require("./routes");

const exphbs = require('express-handlebars');

const Handlebars = require('handlebars');

const handlebarsInstance = exphbs.create({
defaultLayout: 'main',
// Specify helpers which are only registered on this instance.
helpers: {
asJSON: (obj, spacing) => {
if (typeof spacing === "number")
return new Handlebars.SafeString(JSON.stringify(obj, null, spacing));
return new Handlebars.SafeString(JSON.stringify(obj));
}
}
});

app.use("/public", static);
app.use(bodyParser.json());

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

configRoutes(app);

app.listen(3000, () => {
console.log("We've now got a server!");
console.log("Your routes will be running on http://localhost:3000");
});
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const static = express.static(__dirname + "/public");

const configRoutes = require("./routes");

const exphbs = require("express-handlebars");

const Handlebars = require("handlebars");

const handlebarsInstance = exphbs.create({
defaultLayout: "main",
// Specify helpers which are only registered on this instance.
helpers: {
asJSON: (obj, spacing) => {
if (typeof spacing === "number")
return new Handlebars.SafeString(JSON.stringify(obj, null, spacing));

return new Handlebars.SafeString(JSON.stringify(obj));
}
}
});

app.use("/public", static);
app.use(bodyParser.json());

app.engine("handlebars", handlebarsInstance.engine);
app.set("view engine", "handlebars");

configRoutes(app);

app.listen(3000, () => {
console.log("We've now got a server!");
console.log("Your routes will be running on http://localhost:3000");
});
47 changes: 23 additions & 24 deletions Labs/lab_7/config/mongoCollections.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
const dbConnection = require("./mongoConnection");

/* This will allow you to have one reference to each collection per app */
/* Feel free to copy and paste this this */
let getCollectionFn = (collection) => {
let _col = undefined;

return () => {
if (!_col) {
_col = dbConnection().then(db => {
return db.collection(collection);
});
}

return _col;
}
}

/* Now, you can list your collections here: */
module.exports = {
posts: getCollectionFn("posts"),
users: getCollectionFn("users")
};

const dbConnection = require("./mongoConnection");

/* This will allow you to have one reference to each collection per app */
/* Feel free to copy and paste this this */
let getCollectionFn = collection => {
let _col = undefined;

return () => {
if (!_col) {
_col = dbConnection().then(db => {
return db.collection(collection);
});
}

return _col;
};
};

/* Now, you can list your collections here: */
module.exports = {
posts: getCollectionFn("posts"),
users: getCollectionFn("users")
};
48 changes: 24 additions & 24 deletions Labs/lab_7/config/mongoConnection.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const MongoClient = require("mongodb").MongoClient;;

const settings = {
mongoConfig: {
serverUrl: "mongodb://localhost:27017/",
database: "advancedApiBasedBlog"
}
};

let fullMongoUrl = settings.mongoConfig.serverUrl + settings.mongoConfig.database;
let _connection = undefined

let connectDb = () => {
if (!_connection) {
_connection = MongoClient.connect(fullMongoUrl)
.then((db) => {
return db;
});
}

return _connection;
};

module.exports = connectDb;
const MongoClient = require("mongodb").MongoClient;

const settings = {
mongoConfig: {
serverUrl: "mongodb://localhost:27017/",
database: "advancedApiBasedBlog"
}
};

let fullMongoUrl =
settings.mongoConfig.serverUrl + settings.mongoConfig.database;
let _connection = undefined;

let connectDb = () => {
if (!_connection) {
_connection = MongoClient.connect(fullMongoUrl).then(db => {
return db;
});
}

return _connection;
};

module.exports = connectDb;
145 changes: 76 additions & 69 deletions Labs/lab_7/data/events.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,76 @@
const eventList = [
{
id: 0,
attendees: [1, 2],
title: "Dinner at Texas de Brazil",
startTime: new Date("1/15/2016"),
description: "Going out to dinner to a fancy restaurant",
location: 1
},
{
id: 1,
attendees: [1, 2, 3, 4],
title: "Gala",
startTime: new Date("2/07/2016"),
description: "Have to attend a gala for fundraising with other very important people",
location: 2
},
{
id: 2,
attendees: [1, 3, 5],
title: "Fishing Trip",
startTime: new Date("3/29/2016"),
description: "Going fishing!",
location: 3
},
{
id: 3,
attendees: [1, 2, 4, 6],
title: "End of Year Celebration",
startTime: new Date("5/15/2016"),
description: "Going out to dinner to a fancy restaurant, this time to celebrate end of school year",
location: 1
},
{
id: 4,
attendees: [5, 6],
title: "Firework Festival",
startTime: new Date("7/4/2016"),
description: "Let's go watch fireworks at the capital!",
location: 4
},
{
id: 5,
attendees: [5, 1, 2],
title: "End of Summer Party",
startTime: new Date("1/15/2016"),
description: "Let's throw a BBQ for the end of the summer",
location: 5
},
];

let exportedMethods = {
getAllEvents: () => { return Promise.resolve(eventList.slice(0)); },
getEvent: (id) => {
if (id === undefined) return Promise.reject("No id provided");

let event = eventList.filter(x => x.id === id).shift();
if (!event) return Promise.reject("No event found")

return Promise.resolve(event);
},
getEventsForAttendee: (attendeeId) => {
if (attendeesId === undefined) return Promise.reject("No attendee id provided");

return Promise.resolve(eventList.filter(x => x.attendees.indexOf(attendeeId) >= 0));
}
}

module.exports = exportedMethods;
const eventList = [
{
id: 0,
attendees: [1, 2],
title: "Dinner at Texas de Brazil",
startTime: new Date("1/15/2016"),
description: "Going out to dinner to a fancy restaurant",
location: 1
},
{
id: 1,
attendees: [1, 2, 3, 4],
title: "Gala",
startTime: new Date("2/07/2016"),
description:
"Have to attend a gala for fundraising with other very important people",
location: 2
},
{
id: 2,
attendees: [1, 3, 5],
title: "Fishing Trip",
startTime: new Date("3/29/2016"),
description: "Going fishing!",
location: 3
},
{
id: 3,
attendees: [1, 2, 4, 6],
title: "End of Year Celebration",
startTime: new Date("5/15/2016"),
description:
"Going out to dinner to a fancy restaurant, this time to celebrate end of school year",
location: 1
},
{
id: 4,
attendees: [5, 6],
title: "Firework Festival",
startTime: new Date("7/4/2016"),
description: "Let's go watch fireworks at the capital!",
location: 4
},
{
id: 5,
attendees: [5, 1, 2],
title: "End of Summer Party",
startTime: new Date("1/15/2016"),
description: "Let's throw a BBQ for the end of the summer",
location: 5
}
];

let exportedMethods = {
getAllEvents: () => {
return Promise.resolve(eventList.slice(0));
},
getEvent: id => {
if (id === undefined) return Promise.reject("No id provided");

let event = eventList.filter(x => x.id === id).shift();
if (!event) return Promise.reject("No event found");

return Promise.resolve(event);
},
getEventsForAttendee: attendeeId => {
if (attendeesId === undefined)
return Promise.reject("No attendee id provided");

return Promise.resolve(
eventList.filter(x => x.attendees.indexOf(attendeeId) >= 0)
);
}
};

module.exports = exportedMethods;
10 changes: 5 additions & 5 deletions Labs/lab_7/data/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
events: require("./events"),
people: require("./people"),
locations: require("./locations")
};
module.exports = {
events: require("./events"),
people: require("./people"),
locations: require("./locations")
};
Loading

0 comments on commit a6a359e

Please sign in to comment.