mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
finish up implementation for updateEtasForSystemIfTTL
This commit is contained in:
@@ -94,20 +94,54 @@ export class ApiBasedRepository implements GetterRepository {
|
||||
|
||||
public async updateEtasForSystemIfTTL(systemId: string) {
|
||||
try {
|
||||
const params = {
|
||||
eta: "3",
|
||||
stopIds: "177666",
|
||||
};
|
||||
const stops = await this.getStopsBySystemId(systemId);
|
||||
await Promise.all(stops.map(async (stop) => {
|
||||
const params = {
|
||||
eta: "3",
|
||||
stopIds: stop.id,
|
||||
};
|
||||
|
||||
const query = new URLSearchParams(params).toString();
|
||||
const response = await fetch(`${baseUrl}?${query}`, {
|
||||
method: "GET",
|
||||
});
|
||||
const json = await response.json();
|
||||
const query = new URLSearchParams(params).toString();
|
||||
const response = await fetch(`${baseUrl}?${query}`, {
|
||||
method: "GET",
|
||||
});
|
||||
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"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user