I don’t know if this is a bug because it’s shouldn’t be like that at least this is what I think!
Here is the code!
export async function checkIfProductDownloadable(orderId) {
const options = {
suppressAuth: true
};
return wixData.query("Stores/Orders")
.eq("_id", orderId)
.find(options)
.then((requiredOrderData) => {
const requiredOrder = requiredOrderData.items;
if (requiredOrder.length > 0) {
const now = new Date().getTime();
const orderDate = requiredOrder[0]._dateCreated.getTime();
const difference = now - orderDate;
const oneYear = 31556952000;
if (difference > oneYear) {
return 403;
} else {
return 200;
}
}
})
.catch((err) => {
console.error(err);
})
}
In here I’m checking if users order in the last one year or not. And I’m returning 200 (OK) or 403 (Forbidden) as a result for my Router page. I’m using this backend function in a router.js to check orderId.
What I found is if orderId is undefined it returns 200 (I tested in live mode and also in backend preview test) and .eq should not work like that I don’t know if it’s useful in different cases but this is what I think.
Is this a BUG or .eq just works like that?