Help to fix Server Action Workflow

What I am trying to achieve is :
Check if a user (identified with staff_id) has previously attended an event that contains CTF in its name and prevent the user from registering for another CTF event. i.e each user can only register for one CTF event in a lifetime.

I have db Table named event_register which contains all the registration data and has following columns below.
staff_id, event_name, email, name etc.

Below is screenshot of my Server Action which is supposed to

  1. Collect staff_id and event_name from the form.
  2. Check if event_name contains “CTF” (case-insensitive).
  3. If it doesn’t, I let the registration proceed.
  4. If it does, I run a query below to check if that staff_id has previously registered for a CTF event and deny registration :
    SELECT COUNT(*) AS count FROM event_register
    WHERE staff_id =:staff_id AND :event_name LIKE '%CTF%'

Problem is, even with a CTF event selected for staff_id that has CTF record, the registration still goes through.

Grateful for any help to guide me in the right direction

Try changing the condition to IF(checkCTF[0].count.toNumber() > 0) as custom queries typically return arrays of records. (It's a wappler issue - minor but frustrating)

(I'd also personally rename the count variable as count_events or something just for clarity.)

The last 2 lines will never execute as both the "then" and "else" clauses return a response code which ends execution.

You have to use .count()
And after it - .toNumber() is not really needed

Hi the use of LIKE in an sql makes the sql very slow. I would have made a boolean for the CTF event. If you don't want to change this you may have to use a delay before you check for the number of records. Because a sql search with LIKE is not a indexed search.