Skip to content

Commit

Permalink
fixed spelling error crashing app > relates #18 :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dupree committed Oct 5, 2018
1 parent 66adf9c commit e693065
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions controllers/airtable.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// const https = require('https')
// const querystring = require('querystring')
const request = require('request')
let storageUpdaterArr = [];
let airtableArr = [];

module.exports = (req, res, next) => {

Expand All @@ -15,6 +11,8 @@ module.exports = (req, res, next) => {
var base = Airtable.base('apphdQNWTLdRQbOOg');

// set up storageUpdaterArr array to be sent to
let storageUpdaterArr = [];
let airtableArr = [];

// start query to update airtable view no_geolocation
base('fonthilldummy').select({
Expand All @@ -28,17 +26,19 @@ module.exports = (req, res, next) => {
// set up objet to be populated using postcodesIO and sent back to airtable
postcodeIdObj = {
id: record.id,
postcode: record.fields.Postcode,
postcode: record.fields.postcode,
coordinates: {}
}
storageUpdaterArr.push(postcodeIdObj)
});

// create postcode object to be sent to geolocation api
let postcodeObj = {
"postcodes": storageUpdaterArr.map(postcode => {
return postcode.postcode
})
}

request.post('https://api.postcodes.io/postcodes', {
json: postcodeObj,
}, (error, res, body) => {
Expand All @@ -56,6 +56,7 @@ module.exports = (req, res, next) => {
lng: body.result[i].result.longitude
}
}

// send coords and id to update no_geolocation view
for (let i = 0; i < storageUpdaterArr.length; i++) {
base('fonthilldummy').update(storageUpdaterArr[i].id, {
Expand All @@ -81,9 +82,15 @@ module.exports = (req, res, next) => {
// set up objet to be populated using postcodesIO and sent back to airtable
airtableObj = {
id: record.id,
postcode: record.fields.Postcode,
name: record.fields.name,
address: record.fields.address,
priceSqrft: record.fields.price_sqft,
useClass: record.fields.use_class,
dateOfLastRentReview: record.fields.date_of_last_rent_review,
postcode: record.fields.postcode,
coordinates: record.fields.geolocation
}

airtableArr.push(airtableObj);
})
fetchNextPage();
Expand All @@ -93,8 +100,5 @@ module.exports = (req, res, next) => {
res.send({ ...airtableArr })
}
)


);

}

0 comments on commit e693065

Please sign in to comment.