This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
173a1c6
commit a6a359e
Showing
80 changed files
with
21,555 additions
and
16,962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}; |
Oops, something went wrong.