Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GetPlayerVehicle export when querying by vehicleId #9

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ exports('DoesPlayerVehiclePlateExist', doesEntityPlateExist)
---@field props table ox_lib properties table

---@class PlayerVehiclesFilters
---@field vehicleId? number
---@field citizenId? string
---@field states? State|State[]
---@field garage? string

---@param filters? PlayerVehiclesFilters
---@class PlayerVehiclesInternalFilters: PlayerVehiclesFilters
---@field vehicleId? number

---@param filters? PlayerVehiclesInternalFilters
---@return string whereClause, any[] placeholders
local function buildWhereClause(filters)
if not filters then
Expand Down Expand Up @@ -85,9 +87,9 @@ local function buildWhereClause(filters)
return query, placeholders
end

---@param filters? PlayerVehiclesFilters
---@param filters? PlayerVehiclesInternalFilters
---@return PlayerVehicle[]
local function getPlayerVehicles(filters)
local function getPlayerVehiclesInternal(filters)
local query = 'SELECT id, citizenid, vehicle, mods, garage, state, depotprice FROM player_vehicles'
local whereClause, placeholders = buildWhereClause(filters)
local results = MySQL.query.await(query .. whereClause, placeholders)
Expand All @@ -106,8 +108,28 @@ local function getPlayerVehicles(filters)
return ownedVehicles
end

---@param filters? PlayerVehiclesFilters
---@return PlayerVehicle[]
local function getPlayerVehicles(filters)
---@diagnostic disable-next-line: param-type-mismatch
return getPlayerVehiclesInternal(filters)
end

exports('GetPlayerVehicles', getPlayerVehicles)

---@param vehicleId number
---@param filters? PlayerVehiclesFilters
---@return PlayerVehicle?
local function getPlayerVehicle(vehicleId, filters)
if not filters then filters = {} end
---@diagnostic disable-next-line: inject-field
filters.vehicleId = vehicleId
---@diagnostic disable-next-line: param-type-mismatch
return getPlayerVehiclesInternal(filters)[1]
end

exports('GetPlayerVehicle', getPlayerVehicle)

---@class CreatePlayerVehicleRequest
---@field model string model name
---@field citizenid? string owner of the vehicle
Expand Down