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 00:59:22 +0000 |
| commit | 6112f6e099cffd5f1ee1a662398e8eb93bd0525d (patch) | |
| tree | 934816e19713080d5815827e6e0b221d8251ae78 /web/routes/index.js | |
| parent | 858a8dee86de2b2a3214f895dbab850308fd23dc (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 | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/web/routes/index.js b/web/routes/index.js index 23fcf36..f07856a 100644 --- a/web/routes/index.js +++ b/web/routes/index.js @@ -11,9 +11,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, @@ -40,6 +38,30 @@ 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) |
