implemnet getStopById method

This commit is contained in:
2025-01-08 16:49:00 -08:00
parent 17b6f93f0e
commit eef414cdb7

View File

@@ -3,6 +3,10 @@ import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entitie
const baseUrl = "https://passiogo.com/mapGetData.php"
// TODO: add TTL values to everything
// TODO: remove RepositoryDataLoader and UnoptimizedInMemoryRepository
// TODO: make milleseconds (TTL) required on everything
export interface ApiBasedRepositoryCache {
etasForShuttleId?: {
[shuttleId: string]: IEta[],
@@ -13,6 +17,9 @@ export interface ApiBasedRepositoryCache {
stopsBySystemId?: {
[systemId: string]: IStop[],
},
stopByStopId?: {
[stopId: string]: IStop,
},
shuttleByShuttleId?: {
[shuttleId: string]: IShuttle,
},
@@ -115,6 +122,7 @@ export class ApiBasedRepository implements GetterRepository {
}
public async updateEtasForSystemIfTTL(systemId: string) {
// TODO: check if TTL
try {
const stops = await this.getStopsBySystemId(systemId);
await Promise.all(stops.map(async (stop) => {
@@ -224,6 +232,7 @@ export class ApiBasedRepository implements GetterRepository {
}
public async updateShuttlesForSystemIfTTL(systemId: string) {
// TODO: check if TTL
try {
// TODO: update shuttlesByRouteId
// Update shuttleByShuttleId, shuttlesBySystemId
@@ -285,12 +294,20 @@ ${json}`);
}
public async getStopById(stopId: string): Promise<IStop | null> {
// TODO: implement
return null;
if (!this.cache.stopByStopId) return null;
const oldStop = this.cache.stopByStopId[stopId];
if (!oldStop) return null;
await this.updateStopsForSystemIdIfTTL(oldStop.systemId);
const newStop = this.cache.stopByStopId[stopId];
if (!newStop) return null;
return newStop;
}
public async getStopsBySystemId(systemId: string): Promise<IStop[]> {
await this.updateStopsForSystemId(systemId);
await this.updateStopsForSystemIdIfTTL(systemId);
if (!this.cache.stopsBySystemId || this.cache.stopsBySystemId[systemId]) {
return [];
@@ -298,7 +315,9 @@ ${json}`);
return this.cache.stopsBySystemId[systemId];
}
public async updateStopsForSystemId(systemId: string) {
public async updateStopsForSystemIdIfTTL(systemId: string) {
// TODO: check if TTL
try {
const params = {
getStops: "2",