Query based on query works sometimes, but not all the time

I am using the following to code to query my member profiles to use the phone of the logged in member to filter entries in another dataset. It works great as long as there is a phone number in there, if not it gets a undefined result and ignores the .eq in the second query.

$w.onReady(function () {
  var user = wixUsers.currentUser;
  var userId = user.id;
  var isLoggedIn = user.loggedIn;
  user.getEmail()
    .then((email) => {
    let userEmail = email;
	wixData.query("Members/PrivateMembersData")
	 .eq("loginEmail", userEmail)
	 .find()
	 .then((results) => {
		let items = results.items;
		let phone = items[0].mainPhone;
		console.log(items);
		console.log(phone);
		 wixData.query("stallSales")
		  .eq("trainerCellPhone", phone)
		  .find()
		  .then(results => {
		  console.log(results.totalCount)
		  let resultItems = results.items;
		  const showList = resultItems.map(item => item.horseShowId);
		  console.log(resultItems)
		  console.log(showList)
		  $w("#group1").expand();
		  $w('#dataset2').setFilter(wixData.filter()
		 .hasSome("horseShowId", showList)
		)

	})
	})
	})
})

Well either make the phone number a compulsory field so that the field will never be blank, or choose another field to query that you know will also be filled, or write a condition in your code that does something if the phone field is empty or null.

Thanks for the reply, I am thinking the empty or null would be the best way to go but I can’t seem to come up with a code that works. I tried a .isNotEmpty(phone) variation and came up with nothing, would the code be an if results === null or undefined? else if {} type of function?