diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index 18a562e..bf41eb6 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -1,5 +1,5 @@ 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 { 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 { + await this.getShuttlesBySystemId(systemId); + await this.getShuttlesByRouteId(systemId); + await this.getStopsBySystemId(systemId); + await this.getSystemById(systemId); + } + public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise { const shuttle = await this.getShuttleById(shuttleId); const systemId = shuttle?.systemId; @@ -110,7 +124,7 @@ export class ApiBasedRepository implements GetterRepository { return []; } - public async getSystemById(systemId: string): Promise<| null> { + public async getSystemById(systemId: string): Promise { return null; }