From a86ba561ea0c25389d2e3293e90602fad779c13d Mon Sep 17 00:00:00 2001 From: Spythere Date: Sat, 4 Apr 2026 21:13:43 +0200 Subject: [PATCH] refactor(api): changed fetching data from the new api endpoint --- src/store.ts | 5 ++++- src/types/api.types.ts | 5 ++++- src/types/common.types.ts | 1 - src/utils/vehicleUtils.ts | 21 +++++++++++---------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/store.ts b/src/store.ts index b27798c..0c80d9c 100644 --- a/src/store.ts +++ b/src/store.ts @@ -130,7 +130,10 @@ export const useStore = defineStore('store', { async fetchVehiclesAPI() { try { const response = await this.httpClient.get('api/getVehiclesData'); - // this.vehiclesData = response.; + this.vehiclesData = response.vehicles.map((v) => ({ + ...v, + group: response.vehicleGroups.find((g) => g.id == v.vehicleGroupsId)!, + })); console.log(response); } catch (error) { diff --git a/src/types/api.types.ts b/src/types/api.types.ts index c2c1a7a..6f5650b 100644 --- a/src/types/api.types.ts +++ b/src/types/api.types.ts @@ -1,3 +1,5 @@ +import { IVehicleRestrictions } from './common.types'; + // API namespace export namespace API { export namespace VehiclesData { @@ -6,7 +8,8 @@ export namespace API { name: string; type: string; cabinName: string | null; - restrictions: Record | null; + restrictions: IVehicleRestrictions | null; + vehicleGroupsId: number; } diff --git a/src/types/common.types.ts b/src/types/common.types.ts index 6e5bb8f..ac2bb5a 100644 --- a/src/types/common.types.ts +++ b/src/types/common.types.ts @@ -74,7 +74,6 @@ export interface IVehicleData { cabinName: string | null; restrictions: IVehicleRestrictions | null; vehicleGroupsId: number; - simulatorVersion: string; group: IVehicleGroup; } diff --git a/src/utils/vehicleUtils.ts b/src/utils/vehicleUtils.ts index 0d6e0e1..7f65656 100644 --- a/src/utils/vehicleUtils.ts +++ b/src/utils/vehicleUtils.ts @@ -95,16 +95,17 @@ export function carDataList(vehiclesData: IVehicleData[] | undefined) { const cargoTypes = data.group.cargoTypes || []; - if (/412Z|627Z/.test(data.group.name)) { - cargoTypes.push( - ...additionalCargoTypes - .filter((c) => c.groupType == data.group.name) - .map((c) => ({ - id: c.id, - weight: c.weight, - })) - ); - } + // UNUSED - ADDITIONAL CARGO TYPES FOR INTERMODALS + // if (/412Z|627Z/.test(data.group.name)) { + // cargoTypes.push( + // ...additionalCargoTypes + // .filter((c) => c.groupType == data.group.name) + // .map((c) => ({ + // id: c.id, + // weight: c.weight, + // })) + // ); + // } acc.push({ group: data.type as WagonGroupType,