I'm trying to call a await function within a an array.map function.
This is called from frontend to retrieve list from Stripe Products. The stripe product object doesn't return the cost directly it only returns an id which has to be called to return information about the price, the amount.. the currency etc.
getOneToOneProductDetails = async (req, res, next) => {
let products = await stripe.products.list({
limit: 3,
})
products = await products.data.map((product) => {
if(product.active === true)
return {
productId: product.id,
productPrice: product.default_price,
productDescription: product.description,
productName: product.name,
productNumPrice: this.getPrice(product.default_price)
}
})
console.log(products)
res.send(products)
}
getPrice = async(req, res,next) => {
const result = await stripe.prices.retrieve(
req
);
return result.unit_amount
console.log(result)
}
The result I get from the products.data.map is
{
productId: 'prod_MdYuD4PT0HjB7Q',
productPrice: 'price_1LuHn3EIRppAZNR0LNBhUNXN',
productDescription: 'Single Class - 30 Min',
productName: 'Trial Lesson',
productNumPrice: Promise { <pending> }
},
However the getPrice function works fine and returns the required information... I feel like I am unable to call the await function inside the .map function for some reason. I've searched some similar problems but haven't been able to understand the subject as the examples are pretty different from my situation.