refactor route fetching logic for single system ID to external function

This commit is contained in:
2025-01-22 14:27:12 -08:00
parent 5e5f76afcc
commit f1fd774821
2 changed files with 39 additions and 35 deletions

View File

@@ -9,8 +9,8 @@ export class ApiResponseError extends Error {
} }
export class ApiBasedRepositoryLoader { export class ApiBasedRepositoryLoader {
readonly supportedSystemIds = ["263"]; supportedSystemIds = ["263"];
readonly baseUrl = "https://passiogo.com/mapGetData.php"; baseUrl = "https://passiogo.com/mapGetData.php";
constructor( constructor(
public repository: GetterSetterRepository, public repository: GetterSetterRepository,
@@ -51,15 +51,20 @@ export class ApiBasedRepositoryLoader {
} }
} }
public async fetchAndUpdateRouteDataForExistingSystems() { public async fetchAndUpdateRouteDataForExistingSystemsInRepository() {
const systems = await this.repository.getSystems(); const systems = await this.repository.getSystems();
await Promise.all(systems.map(async (system) => { await Promise.all(systems.map(async (system) => {
await this.fetchAndUpdateRouteDataForSystemId(system.id);
}));
}
public async fetchAndUpdateRouteDataForSystemId(systemId: string) {
const params = { const params = {
getRoutes: "2", getRoutes: "2",
}; };
const formDataJsonObject = { const formDataJsonObject = {
"systemSelected0": system.id, "systemSelected0": systemId,
"amount": "1", "amount": "1",
} }
const formData = new FormData(); const formData = new FormData();
@@ -79,13 +84,12 @@ export class ApiBasedRepositoryLoader {
color: jsonRoute.color, color: jsonRoute.color,
id: jsonRoute.myid, id: jsonRoute.myid,
polylineCoordinates: [], polylineCoordinates: [],
systemId: system.id, systemId: systemId,
}; };
await this.repository.addOrUpdateRoute(constructedRoute); await this.repository.addOrUpdateRoute(constructedRoute);
})) }))
} }
}));
} }
public async fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems() { public async fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems() {

View File

@@ -50,7 +50,7 @@ export class TimedApiBasedRepositoryLoader extends ApiBasedRepositoryLoader {
await this.repository.clearSystemData(); await this.repository.clearSystemData();
await this.fetchAndUpdateSystemData(); await this.fetchAndUpdateSystemData();
await this.repository.clearRouteData(); await this.repository.clearRouteData();
await this.fetchAndUpdateRouteDataForExistingSystems(); await this.fetchAndUpdateRouteDataForExistingSystemsInRepository();
await this.repository.clearStopData(); await this.repository.clearStopData();
await this.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems(); await this.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems();
await this.repository.clearShuttleData(); await this.repository.clearShuttleData();