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,9 +94,11 @@ export class ApiBasedRepository implements GetterRepository {
public async updateEtasForSystemIfTTL(systemId: string) {
try {
const stops = await this.getStopsBySystemId(systemId);
await Promise.all(stops.map(async (stop) => {
const params = {
eta: "3",
stopIds: "177666",
stopIds: stop.id,
};
const query = new URLSearchParams(params).toString();
@@ -105,9 +107,41 @@ export class ApiBasedRepository implements GetterRepository {
});
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) {
console.error(e);
}
@@ -168,7 +202,8 @@ export class ApiBasedRepository implements GetterRepository {
public async updateShuttlesForSystemIfTTL(systemId: string) {
try {
// Update shuttleByShuttleId, shuttlesBySystemId, shuttlesByRouteId (future)
// TODO: update shuttlesByRouteId
// Update shuttleByShuttleId, shuttlesBySystemId
const params = {
getBuses: "2"
};