-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lat/long to Request model, rework ID implementation #221
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ exports.systemEmail = '[email protected]'; | |
// of the navigation for the admin section. | ||
exports.signupEnabled = false; | ||
|
||
// Configure Geocoding API API key | ||
exports.googleMapsApiKey = 'AIzaSyB9r-02V9oy8iluVuLweHx6IFi_VuUMXVg'; | ||
|
||
// Make up your own key here. More background: | ||
// | ||
// I believe the cryptoKey is used to server-side sign session data | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: function (queryInterface, Sequelize) { | ||
queryInterface.addColumn('Requests', 'latitude', Sequelize.DOUBLE); | ||
queryInterface.addColumn('Requests', 'longitude', Sequelize.DOUBLE); | ||
}, | ||
|
||
down: function (queryInterface, Sequelize) { | ||
queryInterface.addColumn('Requests', 'latitude'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be |
||
queryInterface.addColumn('Requests', 'longitude'); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,20 +17,25 @@ | |
*/ | ||
|
||
module.exports = function(sequelize, DataTypes) { | ||
return sequelize.define('Request', { | ||
name: DataTypes.TEXT, | ||
address: DataTypes.TEXT, | ||
sms_raw_address: DataTypes.TEXT, | ||
assigned_rc_region: DataTypes.TEXT, | ||
city: DataTypes.TEXT, | ||
state: DataTypes.TEXT, | ||
zip: DataTypes.TEXT, | ||
sms_raw_zip: DataTypes.TEXT, | ||
phone: DataTypes.TEXT, | ||
sms_raw_phone: DataTypes.TEXT, | ||
email: DataTypes.TEXT, | ||
source: DataTypes.TEXT, | ||
serial: { type: DataTypes.TEXT, unique: true }, | ||
status: DataTypes.TEXT | ||
}) | ||
} | ||
return sequelize.define('Request', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, we prefer to minimize whitespace changes to make the diff easier to read. I see you just added the lat/long columns, though. |
||
name: DataTypes.TEXT, | ||
address: DataTypes.TEXT, | ||
sms_raw_address: DataTypes.TEXT, | ||
assigned_rc_region: DataTypes.TEXT, | ||
city: DataTypes.TEXT, | ||
state: DataTypes.TEXT, | ||
zip: DataTypes.TEXT, | ||
sms_raw_zip: DataTypes.TEXT, | ||
phone: DataTypes.TEXT, | ||
sms_raw_phone: DataTypes.TEXT, | ||
email: DataTypes.TEXT, | ||
source: DataTypes.TEXT, | ||
serial: { | ||
type: DataTypes.TEXT, | ||
unique: true | ||
}, | ||
status: DataTypes.TEXT, | ||
latitude: DataTypes.DOUBLE, | ||
longitude: DataTypes.DOUBLE | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
var axios = require('axios'); | ||
var db = require('./../models'); | ||
var config = require('../config'); | ||
var requestData = {}; | ||
|
||
// Config for Google Maps Geocode API | ||
var mapsApiUrl = 'https://maps.googleapis.com/maps/api/geocode/json'; | ||
var mapsApiKey = config.googleMapsApiKey; | ||
|
||
var state_abbrevs = | ||
{ | ||
"Alabama": "AL", | ||
|
@@ -243,6 +249,7 @@ module.exports = { | |
// check again here). | ||
|
||
saveRequestData: function(requestData) { | ||
var savedRequest; | ||
return db.Request.create({ | ||
name: requestData.name, | ||
source: requestData.is_sms, | ||
|
@@ -258,12 +265,36 @@ module.exports = { | |
serial: requestData.serial, | ||
assigned_rc_region: requestData.assigned_rc_region, | ||
status: 'new' | ||
}).catch( function () { | ||
}).then(function(request) { | ||
savedRequest = request; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to me and @kfogel: re-learn about passing vars through the Promise chain. |
||
var query = [ | ||
request.address, | ||
request.city, | ||
request.state, | ||
request.zip | ||
].join(' '); | ||
return axios(mapsApiUrl, { | ||
params: { | ||
key: mapsApiKey, | ||
address: query | ||
} | ||
}); | ||
}).then(function(geocodeResponse) { | ||
console.log(JSON.stringify(geocodeResponse.data.results[0].geometry, null, 2)); | ||
var loc = geocodeResponse.data.results[0].geometry.location; | ||
savedRequest.latitude = loc.latitude; | ||
savedRequest.longitude = loc.longitude; | ||
return savedRequest.save(); | ||
}).catch(function (error) { | ||
console.log(error); | ||
throw error; | ||
/* | ||
// uniqueness failed; increment serial | ||
var serial_array = requestData.serial.split("-"); | ||
var new_serial = module.exports.padWithZeroes((parseInt(serial_array[2]) + 1).toString(), 5); | ||
requestData.serial = serial_array[0] + "-" + serial_array[1] + "-" + new_serial; | ||
return saveRequestData(requestData); //loop until save works | ||
*/ | ||
}); | ||
}, | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @kwhinnery, I see that you removed this in 3dd6ca0. Are you okay with having this in the history or does this mean you need to change your key?