Hello everyone, I am trying to use a single button to make 2 queries in 2 collections, if the conditions of both queries are positive the user can go forward, the 2nd query by itself works well (it is limited to if the user already has 5 items in the collection, a button appears that sends him/her to another page). But I have problems with the first query, it must look to see if the user already has their email in the “Brokers” collection, if not, a button appears that sends them to another area, but if so, the main button with which makes the query and sends it to another area.
First, I don’t know if two queries like these can be made with a single static on_click event, but if so, this code always gives me the action that the user does not have an email, even if the email is in the collection correctly. What am I missing?
I still can’t test the second query together with the first (it is currently all commented with //), since it is only the first one that is not working for me, if we manage to solve the email query, I would remove the comments // and I guess Everything should work fine, I hope for your help my dear friends.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
let user = wixUsers.currentUser.getEmail()
.then((email) => {
console.log(email);
});
export function newInmoButton_click(event) {
wixData.query("Brokers")
.eq("email", user)
.find()
.then((results) => {
if (results.items.length === 0) {
$w('#newInmoButton').hide(),
$w('#warning').hide(),
$w('#planesButton').hide(),
$w('#fichaButton').show(),
$w('#warning2').show()
} else {
$w('#newInmoButton').show()
wixLocation.to(`/corredoreslook/inmuebles-basico/nuevo/${wixUsers.currentUser.id}`)
}
})
// Second query placed as a comment starts here // // // //
wixData.query("Inmuebles")
.eq("_owner", wixUsers.currentUser.id)
.find()
.then((results) => {
// if (results.items.length > 4) {
$w('#newInmoButton').hide(),
$w('#warning').show(),
$w('#planesButton').show(),
$w('#fichaButton').hide(),
$w('#warning2').hide()
} else {
$w('#newInmoButton').show()
wixLocation.to(`/corredoreslook/inmuebles-basico/nuevo/${wixUsers.currentUser.id}`)
// handle case where no matching items found
}
})
// Second query placed as a comment ends here // // // //
.catch((err) => {
console.log(err);
});
}
export function fichaButton_click(event) {
wixLocation.to(`/corredoreslook/update/${wixUsers.currentUser.id}`)
}