diff options
| author | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-02-28 17:09:03 +0000 |
|---|---|---|
| committer | Kumar Damani <kumar.damani@mail.utoronto.ca> | 2019-02-28 17:09:03 +0000 |
| commit | 9eae2a3a228e9fb65970c1e61d9e4f4429def7a1 (patch) | |
| tree | 876de85ab6604611e66c4f1ba94db87056349f52 | |
| parent | 0a61d18ba0088b378fcfab6498b3a1c42f9c029f (diff) | |
changed index to use pointscollection by default
| -rw-r--r-- | web/models/mockpoints.js | 24 | ||||
| -rw-r--r-- | web/models/points.js | 23 | ||||
| -rw-r--r-- | web/routes/index.js | 25 |
3 files changed, 65 insertions, 7 deletions
diff --git a/web/models/mockpoints.js b/web/models/mockpoints.js index 608c0bd..ff5e771 100644 --- a/web/models/mockpoints.js +++ b/web/models/mockpoints.js @@ -1,16 +1,32 @@ var mongoose = require('mongoose'); +// Mongoose Schema definition var Schema = mongoose.Schema; var dumbJsonSchema = new Schema({ type: String, - coordinates: Array + coordinates: Array, + ageRange: String, + clothingDescription: String, + isInjured: Boolean, + reasonForHelp: String }); // Mongoose Model definition var dumbJson = mongoose.model('dumbJstring', dumbJsonSchema, 'dumbpointscollection'); -exports.get_dumb_points = function(callback) { - dumbJson.find({}).exec(function(err, docs){ - callback(err, docs) +// this function gets ALL the points from the db +// returns the entire document without modifications +exports.get_points = function(callback) { + dumbJson.find({}).exec(function(err, docs) { + if (err) callback(err, null); + callback(null, docs); + }); +} + +// this function stores A user report into the db +exports.save_request = function(data, callback) { + dumbJson.create(data, function(err, result) { + if (err) callback(err, null); + callback(null, result); }); } diff --git a/web/models/points.js b/web/models/points.js index 18ffe2e..3a07c82 100644 --- a/web/models/points.js +++ b/web/models/points.js @@ -4,8 +4,29 @@ var mongoose = require('mongoose'); var Schema = mongoose.Schema; var JsonSchema = new Schema({ type: String, - coordinates: Array + coordinates: Array, + ageRange: String, + clothingDescription: String, + isInjured: Boolean, + reasonForHelp: String }); // Mongoose Model definition var Json = mongoose.model('Jstring', JsonSchema, 'pointscollection'); + +// this function gets ALL the points from the db +// returns the entire document without modifications +exports.get_points = function(callback) { + Json.find({}).exec(function(err, docs) { + if (err) callback(err, null); + callback(null, docs); + }); +} + +// this function stores A user report into the db +exports.save_request = function(data, callback) { + Json.create(data, function(err, result) { + if (err) callback(err, null); + callback(null, result); + }); +} diff --git a/web/routes/index.js b/web/routes/index.js index 54c53be..b2d0796 100644 --- a/web/routes/index.js +++ b/web/routes/index.js @@ -11,8 +11,9 @@ router.get('/', function(req, res, next) { /* GET Map page. */ router.get('/map', function(req,res) { - // load the map with mockdata - Mockpoints.get_dumb_points(function(err, points){ + // load the map with all the points + // Mockpoints.get_points(function(err, points){ + Points.get_points(function(err, points){ res.render('map', { lat : 43.665234, lng : -79.383370, @@ -21,4 +22,24 @@ router.get('/map', function(req,res) { }); }); +router.post('/mobilerequest', function(req, res) { + var data = { + 'coordinates': req.body.coordinates, + 'type': req.body.type, + 'isInjured': req.body.isInjured, + 'reasonForHelp': req.body.reasonForHelp, + 'ageRange': req.body.ageRange, + 'clothingDescription': req.body.clothingDescription + } + Points.save_request(data, function(err, result) { + if (err) { + console.log(`err inserting mobile request into db: ${err}`); + res.status(500).send({ error: "boo:(" }); + } else { + console.log(result); + res.status(200).send({'status': 'success', 'data': data}); + } + }); +}); + module.exports = router; |
