Permalink
Browse files

Merge pull request #40 from wtg/development

Merge Development into Master
  • Loading branch information...
JCBird1012 committed May 7, 2017
2 parents 0681a28 + df3a1ba commit cfebf07eddd3479ef8dfd721efdeb994331f16cd
View
@@ -1,4 +1,4 @@
-# Shuttle Signups [![Build Status](https://travis-ci.org/wtg/shuttle-signups.svg?branch=master)](https://travis-ci.org/wtg/shuttle-signups) [![Stories in Ready](https://badge.waffle.io/wtg/shuttle-signups.svg?label=ready&title=Ready)](http://waffle.io/wtg/shuttle-signups) [![Code Climate](https://img.shields.io/codeclimate/github/wtg/shuttle-signups.svg)](https://codeclimate.com/github/wtg/shuttle-signups)[<img align="right" width="150px" src="http://webtech.union.rpi.edu/assets/css/images/wtg.png">](http://webtech.union.rpi.edu/)
+# Shuttle Signups [![Build Status](https://travis-ci.org/wtg/shuttle-signups.svg?branch=master)](https://travis-ci.org/wtg/shuttle-signups) [![Stories in Ready](https://badge.waffle.io/wtg/shuttle-signups.svg?label=ready&title=Ready)](http://waffle.io/wtg/shuttle-signups) [![Code Climate](https://img.shields.io/codeclimate/github/wtg/shuttle-signups.svg)](https://codeclimate.com/github/wtg/shuttle-signups)[<img align="right" width="150px" src="http://webtech.union.rpi.edu/static/wtg.svg">](http://webtech.union.rpi.edu/)
A web interface to simplify the process of signing up for special shuttles at RPI.
View
14 app.js
@@ -48,7 +48,7 @@ const cas = new CASAuthentication({
cas_version: '2.0'
});
-app.get('/', function(req, res, next) {
+app.get('/', (req, res, next) => {
if (req.session && req.session.cas_user) {
res.redirect('/dashboard');
}
@@ -82,20 +82,16 @@ if (!(process.env.NODE_ENV === "development" ||
process.env.NODE_ENV === "production")) {
process.env.NODE_ENV = "production";
}
-//let the developers do things like mocking if running in development.
-if(process.env.NODE_ENV === "development"){
- app.use('/api/mock/',require('./routes/mock/mock'));
-}
-app.get('/login', cas.bounce, function(req, res) {
+app.get('/login', cas.bounce, (req, res) => {
if (!req.session || !req.session.cas_user) {
res.redirect('/logout');
}
res.redirect('/dashboard');
});
-app.get('/dashboard', function(req, res) {
+app.get('/dashboard', (req, res) => {
if (!req.session || !req.session.cas_user) {
res.redirect('/login');
}
@@ -106,7 +102,7 @@ app.get('/dashboard', function(req, res) {
app.get('/logout', cas.logout);
// Catch 404s
-app.use(function(req, res, next) {
+app.use((req, res, next) => {
res.status = 404;
// respond with html page
@@ -128,7 +124,7 @@ app.use(function(req, res, next) {
const port = process.env.PORT || 8080;
-app.listen(port, function() {
+app.listen(port, () => {
console.log('Listening on port ' + port);
console.log('...in ' + process.env.NODE_ENV + ' mode.');
@@ -9,7 +9,7 @@ const helperLib = require("../../helper.js").helpers;
const eventEmitter = require('../../app').eventEmitter;
const helper = new helperLib();
module.exports = router;
-router.post('/', function(req, res) {
+router.post('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
@@ -29,11 +29,11 @@ router.post('/', function(req, res) {
origin: req.body.origin,
departureDate: req.body.departureDate,
}
-
+
var shuttleGroup = new ShuttleGroup(shuttleGroupJSON);
//saves the shuttle group to the database
- shuttleGroup.save(function(err) {
+ shuttleGroup.save((err) => {
if (err) {
console.log("There was a problem saving that shuttle group.");
res.status(500);
@@ -50,4 +50,4 @@ router.post('/', function(req, res) {
res.status(403);
res.send("You don't seem authorized for this action.");
}
-});
+});
@@ -10,7 +10,7 @@ const helperLib = require("../../helper.js").helpers;
const eventEmitter = require('../../app').eventEmitter;
const helper = new helperLib();
module.exports = router;
-router.post('/', function(req, res) {
+router.post('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
@@ -40,7 +40,7 @@ router.post('/', function(req, res) {
var shuttle = new Shuttle(shuttleJSON);
//saves the shuttle to the database
- shuttle.save(function(err, shuttleResult) {
+ shuttle.save((err, shuttleResult) => {
if (err) {
console.log("There was a problem saving a shuttle." + err);
res.status(500);
@@ -9,7 +9,7 @@ const helperLib = require("../../helper.js").helpers;
const eventEmitter = require('../../app').eventEmitter;
const helper = new helperLib();
module.exports = router;
-router.post('/', function(req, res) {
+router.post('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
@@ -28,7 +28,7 @@ router.post('/', function(req, res) {
_id: shuttleID
}, {
isActive: false
- }, function(err) {
+ }, (err) => {
if (err) {
res.send("There was an issue cancelling shuttle " + shuttleID);
return;
@@ -8,7 +8,7 @@ const helperLib = require("../../helper.js").helpers;
const eventEmitter = require('../../app').eventEmitter;
const helper = new helperLib();
module.exports = router;
-router.post('/', function(req, res) {
+router.post('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
res.status(401);
@@ -23,7 +23,7 @@ router.post('/', function(req, res) {
//find and remove shuttle from database
Shuttle.findOneAndRemove({
_id: shuttleID
- }, function(err) {
+ }, (err) => {
if (err) {
res.send("There was an issue deleting shuttle " + shuttleID);
return;
@@ -34,6 +34,7 @@ router.post('/', function(req, res) {
res.send("Shuttle " + shuttleID + " sucessfully deleted.");
return;
});
+
} else {
//deny access if not an admin
res.status(403);
@@ -7,7 +7,7 @@ const Shuttle = require("../../schema/shuttle.js");
const helperLib = require("../../helper.js").helpers;
const helper = new helperLib();
module.exports = router;
-router.post('/', function(req, res) {
+router.post('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
res.status(401);
@@ -27,8 +27,12 @@ router.post('/', function(req, res) {
Shuttle.findOne({
_id: shuttleID
- }, function(err, shuttle) {
+ }, (err, shuttle) => {
// Let's check to see if the shuttles capacity can be lowered...
+ if (err) {
+ res.send("An error has occurred finding the shuttle ID specified.");
+ return;
+ }
if (req.body.maxCapacity < shuttle.maxCapacity) {
if (!(shuttle.riders.length <= req.body.maxCapacity)) {
res.send("This shuttle's capacity cannot be lowered. Doing so would remove riders.");
@@ -54,10 +58,11 @@ router.post('/', function(req, res) {
shuttle.group = req.body.group;
- shuttle.save(function(err) {
+ shuttle.save((err) => {
if (err) {
res.send("There was an error modifying the shuttle.");
console.log(err);
+ return;
}
});
});
@@ -21,7 +21,7 @@ function get_shuttles(ws, req) {
return;
}
- eventEmitter.on('websocket-admin', function(update) {
+ eventEmitter.on('websocket-admin', (update) => {
console.log(update);
ws.send(update);
});
View
@@ -5,7 +5,7 @@ const cms = require('../cms.js');
const helperLib = require("../helper.js").helpers;
const helper = new helperLib();
module.exports = router;
-router.get('/', function(req, res) {
+router.get('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
@@ -18,7 +18,7 @@ router.get('/', function(req, res) {
var rcs_id = req.session.cas_user.toLowerCase();
//parse user_data
- cms.getRCS(rcs_id).then(function(user_data) {
+ cms.getRCS(rcs_id).then((user_data) => {
user_data = JSON.parse(user_data);
// username, student_id (is rin), last_name, middle_name, user_type
res.status(200).json({
@@ -9,7 +9,7 @@ const helperLib = require("../helper.js").helpers;
const eventEmitter = require('../app').eventEmitter;
const helper = new helperLib();
module.exports = router;
-router.get('/', function(req, res) {
+router.get('/', (req, res) => {
//checks if the user is logged in
if (!req.session || !req.session.cas_user) {
@@ -20,7 +20,7 @@ router.get('/', function(req, res) {
// Shuttle groups contain no particularly sensitve information, it's okay to send the same info to users and admins
var query = ShuttleGroup.find({}).lean();
- query.exec(function(err, docs) {
+ query.exec((err, docs) => {
res.send(docs);
});
});
View
@@ -8,7 +8,7 @@ const Shuttle = require("../schema/shuttle.js");
const helperLib = require("../helper.js").helpers;
const helper = new helperLib();
module.exports = router;
-router.get('/', function(req, res) {
+router.get('/', (req, res) => {
//checks if user is logged in
if (!req.session || !req.session.cas_user) {
res.redirect("/login");
@@ -19,7 +19,7 @@ router.get('/', function(req, res) {
if (helper.isAdmin(rcs_id)) {
//query the database and return all information on all shuttles
var query = Shuttle.find({}).lean();
- query.exec(function(err, docs) {
+ query.exec((err, docs) => {
res.send(docs);
});
} else {
@@ -28,7 +28,7 @@ router.get('/', function(req, res) {
query.select('-riders');
query.select('-waitlist');
query.select('-reminderObject');
- query.exec(function(err, docs) {
+ query.exec((err, docs) => {
res.send(docs);
});
}
@@ -7,7 +7,7 @@ const helperLib = require("../helper.js").helpers;
const helper = new helperLib();
const Shuttle = require("../schema/shuttle.js");
module.exports = router;
-router.get('/', function(req, res) {
+router.get('/', (req, res) => {
if (!req.session || !req.session.cas_user) {
res.redirect("/login");
return;
@@ -25,11 +25,15 @@ router.get('/', function(req, res) {
'waitlist': rcs_id
}]
}).lean();
- query.exec(function(err, docs) {
+ query.exec((err, docs) => {
+ if (err) {
+ res.send("An error has occurred retrieving the list of shuttles.");
+ }
res.send(docs);
return;
});
}
+
else {
var query = Shuttle.find({
$or: [{
@@ -44,7 +48,7 @@ router.get('/', function(req, res) {
query.select('waitlist');
query.select('guestsAllowed');
- query.exec(function(err, docs) {
+ query.exec((err, docs) => {
var response = [];
for (var i in docs) {
var numGuests = 0;
@@ -1,6 +0,0 @@
-{
- "username": "develj",
- "first_name": "Johnny",
- "last_name": "Developer",
- "isAdmin": false
-}
@@ -1,48 +0,0 @@
-{
- "data": [{
- "_id": "0001",
- "isActive": true,
- "destination": {
- "longitude": null,
- "latitude": null,
- "name": "Library"
- },
- "origin": {
- "longitude": null,
- "latitude": null,
- "name": "RPI Student Union"
- },
- "message": "I'm from the mock!"
- },
- {
- "_id": "0002",
- "isActive": true,
- "destination": {
- "longitude": null,
- "latitude": null,
- "name": "Russel Sage College"
- },
- "origin": {
- "longitude": null,
- "latitude": null,
- "name": "RPI Student Union"
- },
- "message": "I'm from the mock too!"
- },
- {
- "_id": "1234",
- "isActive": true,
- "destination": {
- "longitude": null,
- "latitude": null,
- "name": "RPI Hockey Rink"
- },
- "origin": {
- "longitude": null,
- "latitude": null,
- "name": "Downtown Albany"
- },
- "message": "I'm from the mock aswell!"
- }
- ]
-}
Oops, something went wrong.

0 comments on commit cfebf07

Please sign in to comment.