Using if statements in a query

Hey team,

I have been testing and playing with this for the past 10 hours and managed to pretty much get my outcome; to display certain text field if conditions are met in a query

function checkAvalibilityDateOne(){
 let course = $w('#dynamicDataset').getCurrentItem()
    wixData.query("CourseAvailability")
        .eq('courseId', course._id)
        .eq('date', course.dateOne)
        .ge('numberOfParticipants', $w('#minParticipantsText').text)
        .find()
        .then((results) => {
 if (results.totalCount > 0){
                $w('#courseStatusConfirmedText').text = "COURSE CONFIRMED"
        }   
    })
}

This code works if the query meets the stored results in the unique database “CourseAvailability” if someone has booked onto the course. For an example, A course has a minimum of 2 people for it to become confirmed, then the text shows if the query meets the above query. All good.

The next step is to try and get $w(‘#courseStatusConfirmedText’).text = “COURSE FULL” to show if the criteria meets the $w(‘#maxParticipantsText’).text) which shows the max participants for the course.

If i could get a little direction on where the area to implement this that would be pretty awesome! Can it be run as if statements in the results of the query?

function checkAvalibilityDateOne(){
 let course = $w('#dynamicDataset').getCurrentItem()
    wixData.query("CourseAvailability")
        .eq('courseId', course._id)
        .eq('date', course.dateOne)
        .ge('numberOfParticipants', $w('#minParticipantsText').text)
        .find()
        .then((results) => {
 if (results.totalCount > 0){
         if ((course.item.minParticipants) => $w('#minParticipantsText').text) {  
                $w('#courseStatusTextSix').text = "COURSE CONFIRMED"
                 }
         if ((course.item.maxParticipants) = $w('#maxParticipantsText').text) {  
                $w('#courseStatusTextSix').text = "FULLY BOOKED"
                 }
        }   
    })
}

The above code doesn’t work but shows what I’m trying to achieve

Many thanks!

Anyone got any help with this one?

Hi,
I’d recommend you to read some articles from wix code basics , you can use the code examples from there in your site.
What are you trying to achieve? What is the use case?