I have an array
containing items
, and I need to incorporate the asynchronous value from getProductMinQuantity
.
The issue I'm facing is that the response with res.status(200)...
gets sent before modifying item.order_quantity_minimum.
I had assumed using a map function like the one below would create a new promise with the updated items.
newResult
is of type Promise<any>[] | undefined
. Hence, I cannot use .then
or .catch
to properly handle my res.status
within it.
const getCart = async () => {
...
let newResult = result.data?.line_items.physical_items.map(async (item: any) =>
item.order_quantity_minimum = await getProductMinQuantity(item.product_id)
)
res.status(200).json({
data: result.data ? normalizeCart(result.data) : null,
})
}
Any suggestions on how I can manage this effectively?