add method to seed the cache for the system id

This commit is contained in:
2025-01-07 20:17:55 -08:00
parent f442c6b279
commit 4ba16bb7c2

View File

@@ -1,5 +1,5 @@
import { GetterRepository } from "./GetterRepository"; import { GetterRepository } from "./GetterRepository";
import { IEta, IOrderedStop, IRoute, IShuttle, IStop } from "../entities/entities"; import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
export interface ApiBasedRepositoryCache { export interface ApiBasedRepositoryCache {
etasForShuttleId?: { etasForShuttleId?: {
@@ -39,6 +39,20 @@ export class ApiBasedRepository implements GetterRepository {
) { ) {
} }
/**
* Seed the initial data in the cache, so data can be updated
* given the correct ID.
* Alternatively, pass in an `initialCache` with existing data
* (useful for testing).
* @param systemId
*/
public async seedCacheForSystemId(systemId: string): Promise<void> {
await this.getShuttlesBySystemId(systemId);
await this.getShuttlesByRouteId(systemId);
await this.getStopsBySystemId(systemId);
await this.getSystemById(systemId);
}
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> { public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> {
const shuttle = await this.getShuttleById(shuttleId); const shuttle = await this.getShuttleById(shuttleId);
const systemId = shuttle?.systemId; const systemId = shuttle?.systemId;
@@ -110,7 +124,7 @@ export class ApiBasedRepository implements GetterRepository {
return []; return [];
} }
public async getSystemById(systemId: string): Promise<| null> { public async getSystemById(systemId: string): Promise<ISystem| null> {
return null; return null;
} }