finish up implementation for updateEtasForSystemIfTTL

This commit is contained in:
2025-01-08 16:08:53 -08:00
parent 0996be0ce3
commit 90f9710a8e

View File

@@ -94,20 +94,54 @@ export class ApiBasedRepository implements GetterRepository {
public async updateEtasForSystemIfTTL(systemId: string) { public async updateEtasForSystemIfTTL(systemId: string) {
try { try {
const params = { const stops = await this.getStopsBySystemId(systemId);
eta: "3", await Promise.all(stops.map(async (stop) => {
stopIds: "177666", const params = {
}; eta: "3",
stopIds: stop.id,
};
const query = new URLSearchParams(params).toString(); const query = new URLSearchParams(params).toString();
const response = await fetch(`${baseUrl}?${query}`, { const response = await fetch(`${baseUrl}?${query}`, {
method: "GET", method: "GET",
}); });
const json = await response.json(); const json = await response.json();
if (json.ETAs && !json.ETAs["0000"]) { if (json.ETAs && json.ETAs[systemId]) {
// Continue with the parsing
json.ETAs[systemId].forEach((jsonEta: any) => {
// Update cache
if (!this.cache.etasForStopId) {
this.cache.etasForStopId = {};
}
if (!this.cache.etasForShuttleId) {
this.cache.etasForShuttleId = {};
}
// TODO: create cache abstraction to deal with possibly undefined properties
if (!this.cache.etasForStopId[stop.id]) {
this.cache.etasForStopId[stop.id] = []
}
const shuttleId: string = jsonEta.busId;
if (!this.cache.etasForShuttleId[shuttleId]) {
this.cache.etasForShuttleId[shuttleId] = [];
}
const eta: IEta = {
secondsRemaining: jsonEta.secondsSpent,
shuttleId: `${shuttleId}`,
stopId: stop.id,
};
this.cache.etasForStopId[stop.id].push(eta);
this.cache.etasForShuttleId[shuttleId].push(eta);
});
}
}));
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@@ -168,7 +202,8 @@ export class ApiBasedRepository implements GetterRepository {
public async updateShuttlesForSystemIfTTL(systemId: string) { public async updateShuttlesForSystemIfTTL(systemId: string) {
try { try {
// Update shuttleByShuttleId, shuttlesBySystemId, shuttlesByRouteId (future) // TODO: update shuttlesByRouteId
// Update shuttleByShuttleId, shuttlesBySystemId
const params = { const params = {
getBuses: "2" getBuses: "2"
}; };