aboutsummaryrefslogtreecommitdiff
path: root/web/routes/index.js
diff options
context:
space:
mode:
authorKumar Damani <kumar.damani@mail.utoronto.ca>2019-03-28 01:07:32 +0000
committerKumar Damani <kumar.damani@mail.utoronto.ca>2019-03-28 01:07:32 +0000
commita2e5a2de701a6e0459538e6894c0be266778351e (patch)
tree2937128e4c241fd31e6b6573a9fc6f4d18df5022 /web/routes/index.js
parent2396a1648de43018749f5a908d6db5a2f0fea7b1 (diff)
parentdbe495f4b3057f476060243503c20f299ac9b385 (diff)
fixed packacge.json conflit, during merge of fix/25 with master
Diffstat (limited to 'web/routes/index.js')
-rw-r--r--web/routes/index.js30
1 files changed, 23 insertions, 7 deletions
diff --git a/web/routes/index.js b/web/routes/index.js
index 23fcf36..1ecce83 100644
--- a/web/routes/index.js
+++ b/web/routes/index.js
@@ -2,7 +2,13 @@ var express = require('express');
var router = express.Router();
var Mockpoints = require('../models/mockpoints');
var Points = require('../models/points');
+var fs = require("fs");
+var GeoJsonGeometriesLookup = require('geojson-geometries-lookup');
+var torontoNeighbourhoords = JSON.parse(fs.readFileSync(__dirname + '/../data/Neighbourhoods.geojson', "utf8"));
+
const connections = [];
+const glookup = new GeoJsonGeometriesLookup(torontoNeighbourhoords);
+
/* GET home page. */
router.get('/', function(req, res, next) {
// for now just redirect to /map
@@ -23,24 +29,34 @@ router.get('/map', function(req,res) {
});
router.post('/mobilerequest', function(req, res) {
- var data = req.body;
- Points.save_request(data, function(err, result) {
+ var point = req.body;
+
+ if (!point.coordinates.length) {
+ var errMssg = "Coordinates field must not be empty in a request.";
+ return res.status(422).send({ error: errMssg });
+ }
+
+ if (!glookup.hasContainers(point)) {
+ var errMssg = "Sorry, we currently only support locations strictly within the City of Toronto.";
+ return res.status(422).send({ error: errMssg });
+ }
+
+ // here we are guaranteed to have a valid point in Toronto
+ Points.save_request(point, function(err, result) {
if (err) {
console.log(`err inserting mobile request into db: ${err}`);
- res.status(500).send({ error: "boo:(" });
+ res.status(500).send({ error: "Sorry, something failed on our end." });
} else {
// send event to all connections
for(var i = 0; i < connections.length; i++) {
- connections[i].sseSend(data);
+ connections[i].sseSend(point);
}
console.log(result);
- res.status(200).send({'status': 'success', 'data': data});
+ res.status(201).send({'status': 'success'});
}
});
-
});
-
router.get('/stream', function(req, res){
// set up server side event (communication line between front end and server)
res.sseSetup();