diff options
| author | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-03-28 00:59:22 +0000 |
|---|---|---|
| committer | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-03-28 01:15:57 +0000 |
| commit | bc966b5e2a4502bf8ad8c7eea9f52ae79f75db87 (patch) | |
| tree | 03da9f18fe70400f1aa93a177a2e260c48f2b2d9 /web/routes/index.js | |
| parent | 4fa6bdbf7f89ff788b231caef84575daabc0ef9f (diff) | |
saving status of point in db. loading only new or pending points in home page
Diffstat (limited to 'web/routes/index.js')
| -rw-r--r-- | web/routes/index.js | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/web/routes/index.js b/web/routes/index.js index 1ecce83..2633c04 100644 --- a/web/routes/index.js +++ b/web/routes/index.js @@ -17,9 +17,7 @@ router.get('/', function(req, res, next) { /* GET Map page. */ router.get('/map', function(req,res) { - // load the map with all the points - // Mockpoints.get_points(function(err, points){ - Points.get_points(function(err, points){ + Points.get_all_active_points(function(err, points){ res.render('map', { lat : 43.665234, lng : -79.383370, @@ -57,6 +55,31 @@ router.post('/mobilerequest', function(req, res) { }); }); +router.post('/savestatus/:status', function(req, res) { + var data = req.body; + var pointId = data.id; + var setStatus = req.params.status; + if ( + setStatus !== "new" && + setStatus !== "pending" && + setStatus !== "complete" + ) { + console.log("Invalid status supplied."); + return res.status(422).send({error: "Error: Status must be one of 'new', 'pending', or 'complete'"}); + } + + // here we are guaranteed to be able to do the query + Points.update_point_status(pointId, setStatus, function(err, result) { + if (err) { + console.log(`err updating point status in db: ${err}`); + res.status(500).send({ error: "Oops. Something went wrong on our end." }); + } else { + console.log(result); + res.status(200).send({'status': 'success'}); + } + }); +}); + router.get('/stream', function(req, res){ // set up server side event (communication line between front end and server) res.sseSetup(); |
