Skip to content

Commit

Permalink
fix: added new getProfiles to qbcore
Browse files Browse the repository at this point in the history
  • Loading branch information
BubbleDK committed Aug 30, 2024
1 parent cea655c commit 49a7bab
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions server/framework/qb_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ local selectProfiles = [[
mdt_profiles profile
ON
profile.citizenid = players.citizenid
LIMIT 10 OFFSET ?
]]

function qb.getAllProfiles()
Expand All @@ -193,6 +194,49 @@ function qb.getAllProfiles()
return profiles
end

local selectProfilesFilter = selectProfiles:gsub('LIMIT', [[
WHERE
players.citizenid LIKE ?
OR CONCAT(
JSON_UNQUOTE(JSON_EXTRACT(players.charinfo, '$.firstname')),
' ',
JSON_UNQUOTE(JSON_EXTRACT(players.charinfo, '$.lastname'))
) LIKE ?
GROUP BY
players.citizenid
LIMIT
]])

function qb.getProfiles(parameters, filter)
local query, params

if filter then
local searchInput = parameters[1]
params = { "%" .. searchInput .. "%", "%" .. searchInput .. "%", parameters[2] }

query = selectProfilesFilter
else
query = selectProfiles
params = parameters
end

local profilesResult = MySQL.rawExecute.await(query, params)
local profiles = {}

for _, v in pairs(profilesResult) do
local charinfo = json.decode(v.charinfo)
profiles[#profiles+1] = {
citizenid = v.citizenid,
firstname = charinfo.firstname,
lastname = charinfo.lastname,
dob = charinfo.birthdate,
image = v.image,
}
end

return profiles
end

function qb.getDriverPoints(citizenid)
local result = MySQL.rawExecute.await('SELECT SUM(COALESCE(points, 0) * COALESCE(count, 1)) AS total_points FROM mdt_incidents_charges WHERE citizenid = ?', { citizenid })?[1]
if (result.total_points) then return result.total_points end
Expand Down

0 comments on commit 49a7bab

Please sign in to comment.