I want to use the node-zillow module to set the value of lastSoldDate but when I go to post I get the error lastSoldDate is undefined. this is what I have so far:
router.route('/add').post((req, res) => {
const address = req.body.address
const street = address.street
const zipcode = address.zipcode
const city = address.city
const state = address.state
paramaters = {
address: address.street,
citystatezip: address.city + ", " + address.state
}
zillow.get('GetDeepSearchResults', paramaters)
.then(function(results) {
date = results.response.results.result[0].lastSoldDate[0]
console.log(date)
return date;
}).then((date) => lastSoldDate = date)
const lastSoldPrice = req.body.lastSoldPrice
const newProperty = new property({
address:{
street,
zipcode,
city,
state,
},
lastSoldDate,
lastSoldPrice
})
newProperty.save()
.then(() => res.json('Property added!'))
.catch(err => res.status(400).json('Error: ' + err))
})