I am having little backend part of code for which the declaration’s variable recPeriod is not visible within the if condition Do not know why: when put the rePeriod
export async function estimeTarif(selChalet, selFrom, selTo, selMbr, group, famille, user) {
let recPeriod = null;
let response = {
"total": 0,
"period": []
}
await createMyParam("periodTarif", user, null, null, null, null, null);
let p1 = await wixData.query("myParams")
.eq("title", "periodTarif")
.eq("userId", user._id)
.find()
.then(async (results) => {
let resExecCount = results.totalCount;
recPeriod = await results.items[0];
if (resExecCount > 0) {
recPeriod = await results.items[0];
}
})
.catch((err) => {
console.error(err);
})
}
When I run only the backend code with the recPeriod outside of the if condition, I am having the result I am looking for.
Now I am having an event in the frontend:
export async function dropdownChalet_change(event) {
selChalet = $w('#dropdownChalet').value;
let calcul = await calculTarif()
if (calcul !== null && calcul !== undefined) {
let tmp = await calcul.toLocaleString();
$w('#tarif').text = tmp;
$w('#adminTarif').text = tmp;
}
selTarif = calcul;
}
That event is calling that next function define below:
export async function calculTarif() {
let dollar = 0;
console.log('calculTarif: "selChalet": ' + selChalet + ' "selFrom": ' + selFrom + ' "selTo": ' + selTo + ' "selMbr": ' + selMbr + ' "group": ' + selGroup + ' "famille": ' + selFamille);
let calcul = await estimeTarif(selChalet, selFrom, selTo, selMbr, selGroup, selFamille, member)
.then((tarif) => {
if (tarif !== null && tarif !== undefined) {
dollar = cout = tarif.total;
periodTarif = tarif.period;
} else {
dollar = cout = 0;
}
})
.catch((err) => {
console.error(err);
});
return dollar;
//const calcul = { "cout": cout, "overCharge": overCharge, "total": total };
}
When calling the backend code from the frontend, I am having no result. meaning cout = 0 and an empty period table for the response’s object.
I am unable to figure out why the frontend call is not working. I used all async and await as necessary.