I am relatively new to Wix, Velo, and Javascript and am trying to compare the userEmail with emails within a database.
I can see the PromiseResult in the console but nothing occurs when I compare.
I’ve tried looking through the API reference and the community forum but I’ve yet to come across anything to directly help my cause.
I’ve found putting a string of one of the email’s within the database in the code works so I was wondering if it was possible to get a string of the email from the PromiseResult of wixUsers . currentUser . getEmail ()
export function button2_click(event) {
let user = wixUsers.currentUser
let userId = user.id
let userEmail = wixUsers.currentUser.getEmail()
wixData.query('members')
.eq('title', userEmail)
.find()
.then(res => {
if (res === 0) {// If email is not in Database
}
else {// If email is in Database
console.log(userEmail)
console.log(res.items)
let count = $w('#dataset1').getTotalCount()
for (var i = 0; i < count; i++) {
let scoreUpdate = res.items[i];
console.log(res.items[i].title)
// VV This line is where I put the direct string rather than the promise userEmail VV
if (res.items[i].title === userEmail){
console.log("Worked")
console.log(scoreUpdate)
scoreUpdate.points = scoreUpdate.points + scoreForQuiz;
wixData.update("members", scoreUpdate);
i = count + 1
}
else{console.log("Not Working")}
}
}
})
}
Any guidance whatsoever would be greatly appreciated.
Thank you in advance