I am trying out to figure out why I am receiving a undefined from the backend .
I often having that issue when having a for loop or foreach function.
BackEnd:
export async function calculTarif(selChalet, selFrom, selTo, selFromNum, selToNum, isMember, isInviter, isVisiteur, selFamMbr, selFamInv, selFamVis, member) {
return wixData.query("myParams")
.eq("title", "Reservation")
.eq("userId", member._id)
.find()
.then(results => {
let rowParam = results.items[0];
console.log("±±±read myparam");
return rowParam;
})
.then(async rowParam => {
//if (rowParam.period !== null && rowParam.period !== undefined) {
let total = 0;
if (period.length > 0) {
await period.forEach(lineItem => {
...
});
}
console.log("±±± to update rowParam ");
rowParam.total = await total;
rowParam.period = await period;
setTimeout(() => {
...
}, 1000);
return rowParam;
})
.then((rowParam) => {
return wixData.update("myParams", rowParam, options)
.then(results => {
console.log("±±±saved myparam");
...
}
I tried using async / await, I also tried to put some settimout() with no clue.:
How can we hold the execution of the next statement to wait for the ending of execution of the current statement?
The last .then() need the data from rowParam, but received undefined when effectively there are data.