Skip to content

Commit

Permalink
feat(server/vehicle): set initVehicle and vehicleProperties states
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Feb 18, 2024
1 parent 9053297 commit aef1093
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion server/vehicle/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export class OxVehicle extends ClassInterface {
model: string,
make: string,
stored: string | null,
metadata: Dict<any>,
id?: number,
vin?: string,
owner?: number,
group?: string,
metadata?: Dict<any>
) {
super();
this.entity = entity;
Expand Down Expand Up @@ -142,6 +142,10 @@ export class OxVehicle extends ClassInterface {
return this.#metadata[key];
}

getState() {
return Entity(this.entity).state;
}

#getSaveData() {
if (!this.id) return;

Expand Down
14 changes: 11 additions & 3 deletions server/vehicle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -87,7 +90,7 @@ export async function CreateVehicle(
data.group || null,
data.model,
vehicleData.class,
data.data || {},
metadata,
data.stored || null
);
}
Expand All @@ -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;
}

Expand Down

0 comments on commit aef1093

Please sign in to comment.