From 4ba16bb7c2e0b4c40c546e503288cc68ad71c22c Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 20:17:55 -0800 Subject: [PATCH] add method to seed the cache for the system id --- src/repositories/ApiBasedRepository.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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; }