I want to add tripPrice
to every object of my array but in the end, tripPrice
is undefined
here is my code:
async getTest(req, res) {
let result = await this.model.Pricing.getTest(req.params);
result.map(async item => {
let params = {
originStation: item.fromStation,
destStation: item.toStation,
cityCode: 1,
carClass: item.carType,
}
let tripPrice = await axios.post(`${appConfig.gpsServer.host}/api/trip/price`, params);
item.price = tripPrice
return item
})
return result
}
how can I add new property to my object after calling an API? it works without async await and API calling