mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
refactor fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId into separate method
This commit is contained in:
@@ -103,12 +103,17 @@ export class ApiBasedRepositoryLoader {
|
|||||||
// Pass JSON output into two different methods to update repository
|
// Pass JSON output into two different methods to update repository
|
||||||
const systems = await this.repository.getSystems();
|
const systems = await this.repository.getSystems();
|
||||||
await Promise.all(systems.map(async (system: ISystem) => {
|
await Promise.all(systems.map(async (system: ISystem) => {
|
||||||
|
await this.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(system.id);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId: string) {
|
||||||
const params = {
|
const params = {
|
||||||
getStops: "2",
|
getStops: "2",
|
||||||
};
|
};
|
||||||
|
|
||||||
const formDataJsonObject = {
|
const formDataJsonObject = {
|
||||||
"s0": system.id,
|
"s0": systemId,
|
||||||
"sA": 1
|
"sA": 1
|
||||||
};
|
};
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -121,10 +126,9 @@ export class ApiBasedRepositoryLoader {
|
|||||||
});
|
});
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|
||||||
await this.updateStopDataForSystemAndApiResponse(system, json);
|
await this.updateStopDataForSystemAndApiResponse(systemId, json);
|
||||||
await this.updateOrderedStopDataForExistingStops(json);
|
await this.updateOrderedStopDataForExistingStops(json);
|
||||||
await this.updatePolylineDataForExistingRoutesAndApiResponse(json);
|
await this.updatePolylineDataForExistingRoutesAndApiResponse(json);
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateShuttleDataForExistingSystems() {
|
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) {
|
if (json.stops) {
|
||||||
const jsonStops = Object.values(json.stops);
|
const jsonStops = Object.values(json.stops);
|
||||||
|
|
||||||
@@ -216,7 +220,7 @@ export class ApiBasedRepositoryLoader {
|
|||||||
const constructedStop: IStop = {
|
const constructedStop: IStop = {
|
||||||
name: stop.name,
|
name: stop.name,
|
||||||
id: stop.id,
|
id: stop.id,
|
||||||
systemId: system.id,
|
systemId,
|
||||||
coordinates: {
|
coordinates: {
|
||||||
latitude: parseFloat(stop.latitude),
|
latitude: parseFloat(stop.latitude),
|
||||||
longitude: parseFloat(stop.longitude),
|
longitude: parseFloat(stop.longitude),
|
||||||
|
|||||||
Reference in New Issue
Block a user