From 0a61d18ba0088b378fcfab6498b3a1c42f9c029f Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Thu, 28 Feb 2019 00:40:15 -0700 Subject: sending geo data to front end, displaying it as markers, and taken out schema defs from index into models folder --- web/routes/index.js | 51 +++++++++------------------------------------------ 1 file changed, 9 insertions(+), 42 deletions(-) (limited to 'web/routes') diff --git a/web/routes/index.js b/web/routes/index.js index df579fc..54c53be 100644 --- a/web/routes/index.js +++ b/web/routes/index.js @@ -1,56 +1,23 @@ var express = require('express'); var router = express.Router(); - -// Mongoose import -var mongoose = require('mongoose'); - -var env = process.env.NODE_ENV || 'development'; -var uri; -if (env === 'development') { - uri = 'mongodb://localhost:27017/helpthehome' - // use for small testing only if really necessary - // uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' -} else if (env === 'qa') { - uri = process.env.MONGODB_URI -} else if (env === 'production') { - uri = '' -} - -// Mongoose connection to MongoDB -mongoose.connect(uri, { useNewUrlParser: true }, function (error) { - if (error) { - console.log(error); - console.log("App was not able to connect to the mongo server!"); - console.log("... double check that the mongo server is running locally"); - } else { - console.log(`connected to ${uri}`); - } -}); - -// Mongoose Schema definition -var Schema = mongoose.Schema; -var JsonSchema = new Schema({ - name: String, - type: Schema.Types.Mixed, - coordinates: Array -}); - -// Mongoose Model definition -var Json = mongoose.model('Jstring', JsonSchema, 'pointscollection'); +var Mockpoints = require('../models/mockpoints'); +var Points = require('../models/points'); /* GET home page. */ router.get('/', function(req, res, next) { // for now just redirect to /map - //res.render('index', { title: 'Welcome' }); res.redirect('/map'); }); /* GET Map page. */ router.get('/map', function(req,res) { - // send the view lat, and long. city center - res.render('map', { - lat : 43.654127, - lng : -79.383370 + // load the map with mockdata + Mockpoints.get_dumb_points(function(err, points){ + res.render('map', { + lat : 43.665234, + lng : -79.383370, + points: points + }); }); }); -- cgit v1.2.3 From 9eae2a3a228e9fb65970c1e61d9e4f4429def7a1 Mon Sep 17 00:00:00 2001 From: Kumar Damani Date: Thu, 28 Feb 2019 10:09:03 -0700 Subject: changed index to use pointscollection by default --- web/routes/index.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'web/routes') 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; -- cgit v1.2.3