Skip to content

Commit 5470f15

Browse files
committed
fix(server/vehicle): ensure vehicle.data is an object
1 parent 590df23 commit 5470f15

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

server/vehicle/class.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export class OxVehicle extends ClassInterface {
208208

209209
despawn(save?: boolean) {
210210
emit('ox:despawnVehicle', this.entity, this.id);
211-
211+
212212
const saveData = save && this.#getSaveData();
213213
if (saveData) SaveVehicleData(saveData);
214214
if (DoesEntityExist(this.entity)) DeleteEntity(this.entity);
@@ -254,7 +254,7 @@ export class OxVehicle extends ClassInterface {
254254
}
255255

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

259259
if (apply) setVehicleProperties(this.entity, this.#properties);
260260
}

server/vehicle/db.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ export async function IsVinAvailable(plate: string) {
2121
return !(await db.exists('SELECT 1 FROM vehicles WHERE vin = ?', [plate]));
2222
}
2323

24-
export function GetStoredVehicleFromId(id: number) {
25-
return db.row<VehicleRow>(
24+
export async function GetStoredVehicleFromId(id: number) {
25+
const row = await db.row<VehicleRow>(
2626
'SELECT id, owner, `group`, plate, vin, model, data FROM vehicles WHERE id = ? AND `stored` IS NOT NULL',
2727
[id]
2828
);
29+
30+
if (row && typeof row.data === 'string') {
31+
console.warn(
32+
`vehicle.data was selected from the database as a string rather than JSON.\nLet us know if this warning occurred..`
33+
);
34+
row.data = JSON.parse(row.data);
35+
}
36+
37+
return row;
2938
}
3039

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

0 commit comments

Comments
 (0)