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
|
||||
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),
|
||||
|
||||
Reference in New Issue
Block a user