diff --git a/server/vehicle/class.ts b/server/vehicle/class.ts index 341616d6..a367326d 100644 --- a/server/vehicle/class.ts +++ b/server/vehicle/class.ts @@ -107,11 +107,11 @@ export class OxVehicle extends ClassInterface { model: string, make: string, stored: string | null, + metadata: Dict, id?: number, vin?: string, owner?: number, group?: string, - metadata?: Dict ) { super(); this.entity = entity; @@ -142,6 +142,10 @@ export class OxVehicle extends ClassInterface { return this.#metadata[key]; } + getState() { + return Entity(this.entity).state; + } + #getSaveData() { if (!this.id) return; diff --git a/server/vehicle/index.ts b/server/vehicle/index.ts index 3f84640e..b864726f 100644 --- a/server/vehicle/index.ts +++ b/server/vehicle/index.ts @@ -79,6 +79,9 @@ export async function CreateVehicle( data.plate = data.plate && (await IsPlateAvailable(data.plate)) ? data.plate : await OxVehicle.generatePlate(); + const metadata = data.data || {}; + metadata.properties = metadata.properties || data.properties; + if (!data.id && data.vin) { data.id = await CreateNewVehicle( data.plate, @@ -87,7 +90,7 @@ export async function CreateVehicle( data.group || null, data.model, vehicleData.class, - data.data || {}, + metadata, data.stored || null ); } @@ -101,15 +104,20 @@ export async function CreateVehicle( data.model, vehicleData.make, data.stored || null, + metadata, data.id, data.vin, data.owner, - data.group, - data.data + data.group ); if (vehicle.id) vehicle.setStored(null, false); + const state = vehicle.getState(); + + state.set('initVehicle', true, true); + state.set('vehicleProperties', metadata.properties, true); + return vehicle; }