mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
implement getStopsBySystemId and updateStopsForSystemId
This commit is contained in:
@@ -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([]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user