mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add method to fetch and update shuttle data
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { IRoute, ISystem, Repository } from "./repository";
|
||||
import { IRoute, IShuttle, ISystem, Repository } from "./repository";
|
||||
|
||||
const timeout = 10000;
|
||||
const systemIdsToSupport = ["263"]
|
||||
const systemIdsToSupport = ["263", "3215"];
|
||||
const baseUrl = "https://passiogo.com/mapGetData.php";
|
||||
|
||||
export class RepositoryDataLoader {
|
||||
@@ -31,8 +31,8 @@ export class RepositoryDataLoader {
|
||||
try {
|
||||
await this.fetchAndUpdateSystemData();
|
||||
await this.fetchAndUpdateRouteDataForExistingSystems();
|
||||
await this.fetchAndUpdateStopAndOrderedStopData();
|
||||
await this.fetchAndUpdateShuttleData();
|
||||
await this.fetchAndUpdateStopAndPolylineDataForRoutes();
|
||||
await this.fetchAndUpdateShuttleDataForSystems();
|
||||
await this.fetchAndUpdateEtaData();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -103,12 +103,53 @@ export class RepositoryDataLoader {
|
||||
}));
|
||||
}
|
||||
|
||||
private async fetchAndUpdateStopAndOrderedStopData() {
|
||||
private async fetchAndUpdateStopAndPolylineDataForRoutes() {
|
||||
|
||||
}
|
||||
|
||||
private async fetchAndUpdateShuttleData() {
|
||||
private async fetchAndUpdateShuttleDataForSystems() {
|
||||
const systems = await this.repository.getSystems();
|
||||
await Promise.all(systems.map(async (system: ISystem) => {
|
||||
const params = {
|
||||
getBuses: "2"
|
||||
};
|
||||
|
||||
const formDataJsonObject = {
|
||||
"s0": system.id,
|
||||
"sA": "1"
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
formData.set("json", JSON.stringify(formDataJsonObject));
|
||||
|
||||
const query = new URLSearchParams(params).toString();
|
||||
const response = await fetch(`${baseUrl}?${query}`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
const json = await response.json();
|
||||
|
||||
if (json.buses && json.buses["-1"] === undefined) {
|
||||
const jsonBuses = Object.values(json.buses).map((busesArr: any) => {
|
||||
return busesArr[0];
|
||||
});
|
||||
|
||||
await Promise.all(jsonBuses.map(async (jsonBus: any) => {
|
||||
const constructedShuttle: IShuttle = {
|
||||
name: jsonBus.bus,
|
||||
coordinates: {
|
||||
latitude: parseFloat(jsonBus.latitude),
|
||||
longitude: parseFloat(jsonBus.longitude),
|
||||
},
|
||||
routeId: jsonBus.routeId,
|
||||
systemId: system.id,
|
||||
id: `${jsonBus.busId}`
|
||||
}
|
||||
|
||||
await this.repository.addOrUpdateShuttle(constructedShuttle);
|
||||
}))
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private async fetchAndUpdateEtaData() {
|
||||
|
||||
Reference in New Issue
Block a user