refactor fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId into separate method

This commit is contained in:
2025-01-22 14:55:51 -08:00
parent 4d5e563f9c
commit b2be3ae583

View File

@@ -103,12 +103,17 @@ export class ApiBasedRepositoryLoader {
// Pass JSON output into two different methods to update repository
const systems = await this.repository.getSystems();
await Promise.all(systems.map(async (system: ISystem) => {
await this.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(system.id);
}));
}
public async fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId: string) {
const params = {
getStops: "2",
};
const formDataJsonObject = {
"s0": system.id,
"s0": systemId,
"sA": 1
};
const formData = new FormData();
@@ -121,10 +126,9 @@ export class ApiBasedRepositoryLoader {
});
const json = await response.json();
await this.updateStopDataForSystemAndApiResponse(system, json);
await this.updateStopDataForSystemAndApiResponse(systemId, json);
await this.updateOrderedStopDataForExistingStops(json);
await this.updatePolylineDataForExistingRoutesAndApiResponse(json);
}));
}
public async fetchAndUpdateShuttleDataForExistingSystems() {
@@ -208,7 +212,7 @@ export class ApiBasedRepositoryLoader {
}))
}
protected async updateStopDataForSystemAndApiResponse(system: ISystem, json: any) {
protected async updateStopDataForSystemAndApiResponse(systemId: string, json: any) {
if (json.stops) {
const jsonStops = Object.values(json.stops);
@@ -216,7 +220,7 @@ export class ApiBasedRepositoryLoader {
const constructedStop: IStop = {
name: stop.name,
id: stop.id,
systemId: system.id,
systemId,
coordinates: {
latitude: parseFloat(stop.latitude),
longitude: parseFloat(stop.longitude),