So I have a function that calls my API:
const trackPurchase = async (customerId, unitsPurchased) => {
const response = await fetch("http://localhost:5000/purchases", {
method: "POST",
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
"customerId": customerId,
"unitsPurchased": unitsPurchased
})
})
return await response.text()
};
module.exports = { trackPurchase };
In another file I call the above function:
const trackPurchases = async () => {
try {
const units = await trackPurchase (123, 1)
return units
} catch (error) {
console.log("ERROR ",error)
}
};
console.log(
"trackPurchases ",
trackPurchases ()
)
Logging the result I get a promise. Meanwhile, the request succeeded and the database is updated. What am I missing? Why isn't the promise resolving?