diff --git a/server/main.lua b/server/main.lua index 50bbe4f..17b6339 100644 --- a/server/main.lua +++ b/server/main.lua @@ -57,6 +57,18 @@ local function buildWhereClause(filters) end local placeholders = {} local whereClauseCrumbs = {} + if filters.vehicleId then + whereClauseCrumbs[#whereClauseCrumbs+1] = 'id = ?' + placeholders[#placeholders+1] = filters.vehicleId + end + if filters.citizenid then + whereClauseCrumbs[#whereClauseCrumbs+1] = 'citizenid = ?' + placeholders[#placeholders+1] = filters.citizenid + end + if filters.garage then + whereClauseCrumbs[#whereClauseCrumbs+1] = 'garage = ?' + placeholders[#placeholders+1] = filters.garage + end if filters.states then if type(filters.states) ~= 'table' then ---@diagnostic disable-next-line: assign-type-mismatch @@ -68,21 +80,9 @@ local function buildWhereClause(filters) placeholders[#placeholders+1] = filters.states[i] statePlaceholders[i] = 'state = ?' end - whereClauseCrumbs[#whereClauseCrumbs+1] = table.concat(statePlaceholders, ' OR ') + whereClauseCrumbs[#whereClauseCrumbs+1] = string.format('(%s)', table.concat(statePlaceholders, ' OR ')) end end - if filters.vehicleId then - whereClauseCrumbs[#whereClauseCrumbs+1] = 'id = ?' - placeholders[#placeholders+1] = filters.vehicleId - end - if filters.citizenid then - whereClauseCrumbs[#whereClauseCrumbs+1] = 'citizenid = ?' - placeholders[#placeholders+1] = filters.citizenid - end - if filters.garage then - whereClauseCrumbs[#whereClauseCrumbs+1] = 'garage = ?' - placeholders[#placeholders+1] = filters.garage - end return string.format(' WHERE %s', table.concat(whereClauseCrumbs, ' AND ')), placeholders end