You should delete the await from your query. You are using a .then() so the await is an error. And therefore, you don’t need async in the function definition.
You need to return your results inside of the query’s .then() function. And, you also need to return the result of the Promise’s then().
Big thanks for the advise @yisrael-wix . I transformed all the promise call as suggested. It seems to work well in the backend. All object in return has data.
But I always receive undefined while calling it from the frontend. So I converted the frontend call in the backend to see the result. I am receiving a message from the Wix editor that the function is a type void. Here the message received from the converted backend function:
See the getTarifReserv function. Is it right to say this is because of the void function I am receiving an undefined
export function getTarifReserv(user) {
return wixData.query("myParams")
.eq("title", "Reservation")
.eq("userId", user._id)
.find()
.then((results) => {
let rowParam = results.items[0];
if (rowParam !== null && rowParam !== undefined) {
return {
"total": rowParam.cout,
"period": rowParam.period
};
} else {
let err = "getTarifReserv: 2 ERREUR Logique, pas de record MyParams pour Reservation pour userID = " + user._id;
console.error(err);
return {
"total": 0,
"period": []
};
}
})
.catch((err) => {
console.error(err);
})
}
Can you help for that part too. to resolve the undefined problem. Here is the front end function:
@yisrael-wix :
I am having a scenario where I am not sure how I would chain all the then Promise call: and all the parameter that need to be passed till the last level of chain call.
How would you rewrite the promiseCall
export function ABC(p1, p2, p3, p4) {
I need to convert p1 and p2.
d1 = promiseCallD(p1);
d2 = promiseCallD(p2);
let isActive = true;
while (isActive) {
wixData.query("collection")
.eq("d1", d1)
.lt("d2"), d2)
.find()
.then (results => {
row = results.items[0];
...
return {"data":row.data,
"d1": d1,
"d2": d2
};
})
.then (res => {
let tmp = null
f1 = PromiseCallF(p3, res.d1);
f2 = PromiseCallF(p4, res.d2);
row = {"f1": f1,
"f2": f2,
"d1": d1,
"d2": d2
};
return tbl.push(row); =
})
}
return data
}
Saying that a Promise call should be code like that: