Skip to content

Commit

Permalink
fix(server/vehicle): ensure vehicle.data is an object
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Jan 27, 2025
1 parent 590df23 commit 5470f15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions server/vehicle/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class OxVehicle extends ClassInterface {

despawn(save?: boolean) {
emit('ox:despawnVehicle', this.entity, this.id);

const saveData = save && this.#getSaveData();
if (saveData) SaveVehicleData(saveData);
if (DoesEntityExist(this.entity)) DeleteEntity(this.entity);
Expand Down Expand Up @@ -254,7 +254,7 @@ export class OxVehicle extends ClassInterface {
}

setProperties(properties: VehicleProperties, apply?: boolean) {
this.#properties = properties;
this.#properties = typeof properties === 'string' ? JSON.parse(properties) : properties;

if (apply) setVehicleProperties(this.entity, this.#properties);
}
Expand Down
13 changes: 11 additions & 2 deletions server/vehicle/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ export async function IsVinAvailable(plate: string) {
return !(await db.exists('SELECT 1 FROM vehicles WHERE vin = ?', [plate]));
}

export function GetStoredVehicleFromId(id: number) {
return db.row<VehicleRow>(
export async function GetStoredVehicleFromId(id: number) {
const row = await db.row<VehicleRow>(
'SELECT id, owner, `group`, plate, vin, model, data FROM vehicles WHERE id = ? AND `stored` IS NOT NULL',
[id]
);

if (row && typeof row.data === 'string') {
console.warn(
`vehicle.data was selected from the database as a string rather than JSON.\nLet us know if this warning occurred..`
);
row.data = JSON.parse(row.data);
}

return row;
}

export async function SetVehicleColumn(id: number | void, column: string, value: any) {
Expand Down

0 comments on commit 5470f15

Please sign in to comment.