implement getStopsBySystemId and updateStopsForSystemId

This commit is contained in:
2025-01-08 16:19:11 -08:00
parent 3829286ec4
commit 88dbce007d

View File

@@ -266,7 +266,59 @@ ${json}`);
}
public async getStopsBySystemId(systemId: string): Promise<IStop[]> {
return [];
await this.updateStopsForSystemId(systemId);
if (!this.cache.stopsBySystemId || this.cache.stopsBySystemId[systemId]) {
return [];
}
return this.cache.stopsBySystemId[systemId];
}
public async updateStopsForSystemId(systemId: string) {
try {
const params = {
getStops: "2",
};
const formDataJsonObject = {
"s0": systemId,
"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();
// TODO: update polyline data
// TODO: update ordered stop data
if (json.stops) {
const jsonStops = Object.values(json.stops);
await Promise.all(jsonStops.map(async (stop: any) => {
const constructedStop: IStop = {
name: stop.name,
id: stop.id,
systemId: systemId,
coordinates: {
latitude: parseFloat(stop.latitude),
longitude: parseFloat(stop.longitude),
},
};
if (this.cache.stopsBySystemId) {
this.cache.stopsBySystemId[systemId]?.push(constructedStop);
}
}));
}
} catch (e) {
}
}
public async getSystemById(systemId: string): Promise<ISystem| null> {
@@ -276,4 +328,5 @@ ${json}`);
public async getSystems(): Promise<[]> {
return Promise.resolve([]);
}
}