doug_w
11/21/2017, 6:46 PMREQUEST PIPELINE -> ADDRESS IS CREATED
. Basically before an Address is saved in the database, the function should use the Google Maps API to get the geolocation information and add it to the address before save. The promise
to get the geolocation info works in a regular node ENV. I am unable to use the info my promise returns in order to tac it on to the address. The event always comes back blank.
'use strict'
const googleMapsClient = require('@google/maps').createClient({
key: 'SUPER_KEY'
})
const getGeolocation = (address) =>
new Promise((resolve, reject) => {
googleMapsClient.geocode({
address: address
}, (err, response) => {
if(err) {
resolve(err)
} else {
const locationResult = response.json.results[0].geometry.location
const geolocation = {
lat: locationResult.lat,
lng: locationResult.lng,
isGeolocated: true
}
resolve(geolocation)
}
})
})
module.exports = function (event) {
getGeolocation('1600 Amphitheatre Parkway, Mountain View, CA')
.then(geolocation => {
event.data.lat = geolocation.lat
event.data.lng = geolocation.lng
event.data.isGeolocated = geolocation.isGeolocated
return {data: event.data}
})
.catch(err => console.log(err))
return event
}
Is this not a proper use case for this type of function?
Edit I have dumbed down my initial approach a lot. I can not get it to modify the input, or return any value what’s so ever:
export default event => {
console.log(`event: ${event}`)
event.data.billingPhone = "3333333"
return event
}