Check if the boolean is checked

Hello, I have written this code`

import wixData from 'wix-data';
import wixLocation from 'wix-location';

export function button12_click(event, $w) {
 let nfc = $w('#nfc').value;
    wixData.query("AllStudents")
        .eq('nfcId', nfc)
        .find()
        .then((results) => {
 if (results.items.length > 0) {
                wixLocation.to(`/pttcowp-student/clubcard/${results.items[0]._id}`);
            }
 if (results.items.length === 0) {
                $w('#text113').show();
            }
        })
        .catch((err) => {

            console.log("err", err);
        });

}

Before going to the dynamic page, I want the code to check if the filed “status” in the database is checked. If it is checked then it will take me to the dynamic page, If it is not, it will show the error text,
Please, can someone tell me how can I make this work?
Thanks in advance!!

Hello,

I noticed you have two if statements, you can combine these and it will have the same effect, given how results come back. All you need is another conditional check to see if the status is true or false like I added below.

 wixData.query("AllStudents") 
 .eq('nfcId', nfc) 
 .find() 
 .then((results) => { 
       if (results.items.length > 0 && results.items[0].status) { 
       wixLocation.to(`/pttcowp-student/clubcard/${results.items[0]._id}`); 
       } else {
        $w('#text113').show(); 
       }
 }) 
   .catch((err) => {             
   console.log("err", err);
 }); 

Hope this helps,
Majd

Wow, Works as I Need!!! Dear Majd, Thank You Very Very Much!!!

Glad to help :)!