I am trying to set the value of a variable from the queries I am making, but for whatever reason, is just doesn’t want to, and I cannot find anything to explain it. My code looks just like what it should be based on the API, as far as I can tell.
function checkEmailAgainstPrivateMembers() {
var tutorQueryResults;
var studentQueryResults;
wixData.query("Members/PrivateMembersData")
.contains("loginEmail", $w('#tutorEmail').value)
.find()
.then( (results) => {
tutorQueryResults = results;
console.log(tutorQueryResults.totalCount, " results found.");
console.log(tutorQueryResults.items);
} );
wixData.query("Members/PrivateMembersData")
.contains("loginEmail", $w('#studentEmail').value)
.find()
.then( (results) => {
studentQueryResults = results;
console.log(studentQueryResults.totalCount, " results found.");
console.log(studentQueryResults.items);
} );
console.log("Tutor email query results: ", tutorQueryResults);
console.log("Student email query results: ", studentQueryResults);
if (tutorQueryResults === 1 && studentQueryResults === 1 && $w('#tutorEmail').value.length !== 0 && $w('#studentEmail').value.length !== 0) {
console.log("Tutor email provided: ", $w('#tutorEmail').value);
console.log("Student email provided: ", $w('#studentEmail').value);
console.log("checkEmailAgainstPrivateMembers() returned TRUE");
return true;
} else {
console.log("Tutor email provided: ", $w('#tutorEmail').value);
console.log("Student email provided: ", $w('#studentEmail').value);
console.log("checkEmailAgainstPrivateMembers() returned FALSE")
//
// Change return value to 'true' for testing without checking input email against Wix Member table
//
return false;
}