diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index 5eb963e..b7d5cc0 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -84,12 +84,34 @@ export class ApiBasedRepository implements GetterRepository { return null; } - public async getEtasForShuttleId(shuttleId: string): Promise<[]> { - return []; + public async getEtasForShuttleId(shuttleId: string): Promise { + const shuttle = await this.getShuttleById(shuttleId); + const systemId = shuttle?.systemId; + if (!systemId) { + return []; + } + await this.updateEtasForSystemIfTTL(systemId); + + if (!this.cache?.etasForShuttleId || !this.cache.etasForShuttleId[shuttleId]) { + return []; + } + + return this.cache.etasForShuttleId[shuttleId]; } - public async getEtasForStopId(stopId: string): Promise<[]> { - return []; + public async getEtasForStopId(stopId: string): Promise { + const stop = await this.getStopById(stopId); + const systemId = stop?.systemId; + if (!systemId) { + return []; + } + await this.updateEtasForSystemIfTTL(systemId); + + if (!this.cache?.etasForStopId || !this.cache.etasForStopId[stopId]) { + return []; + } + + return this.cache.etasForStopId[stopId]; } public async updateEtasForSystemIfTTL(systemId: string) { @@ -262,7 +284,8 @@ ${json}`); } } - public async getStopById(stopId: string): Promise<| null> { + public async getStopById(stopId: string): Promise { + // TODO: implement return null; }