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,9 +94,11 @@ export class ApiBasedRepository implements GetterRepository {
|
|||||||
|
|
||||||
public async updateEtasForSystemIfTTL(systemId: string) {
|
public async updateEtasForSystemIfTTL(systemId: string) {
|
||||||
try {
|
try {
|
||||||
|
const stops = await this.getStopsBySystemId(systemId);
|
||||||
|
await Promise.all(stops.map(async (stop) => {
|
||||||
const params = {
|
const params = {
|
||||||
eta: "3",
|
eta: "3",
|
||||||
stopIds: "177666",
|
stopIds: stop.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
@@ -105,9 +107,41 @@ export class ApiBasedRepository implements GetterRepository {
|
|||||||
});
|
});
|
||||||
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"
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user