I am trying to get data from one endpoint and use it to hit another endpoint before I send the data to my frontend. I have tried a number of different async await combinations but the res.status.json always resolves before I manage to get the getAirport function to resolve. Any ideas on how I can get it to wait?
router.get("", (req, res, next) => {
sabre
.get("/v1/lists/supported/cities")
.then(response => {
let cities = response.data.Cities;
let citiesObj = cities.map(city => {
//console.log('here');
return {
name: city.name,
code: city.code,
airports: city.Links.map(link => {
return getAirport(link["href"]);
})
};
});
res.status(200).json({ message: "ok", data: citiesObj });
})
.catch(err => console.log(err));
});
function getAirport(link) {
let updatedUrl = link.replace(baseUrl, "");
return sabre.get(updatedUrl);
}
https://stackoverflow.com/questions/ask#