From 1958af2593c20a66f45a19464ead858d18626024 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Tue, 7 Jan 2025 19:54:39 -0800 Subject: [PATCH] write logic to get eta for shuttle and stop id --- src/repositories/ApiBasedRepository.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index a3d4c67..18a562e 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -40,6 +40,20 @@ export class ApiBasedRepository implements GetterRepository { } public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise { + const shuttle = await this.getShuttleById(shuttleId); + const systemId = shuttle?.systemId; + if (!systemId) { + return null; + } + + if (this.initialCache?.etasForStopId !== undefined) { + const etas = this.initialCache.etasForStopId[systemId]; + const foundEta = etas.find((eta) => eta.stopId === stopId); + if (foundEta) { + return foundEta; + } + } + return null; } @@ -76,7 +90,7 @@ export class ApiBasedRepository implements GetterRepository { return Promise.resolve([]); } - public async getShuttleById(shuttleId: string): Promise<| null> { + public async getShuttleById(shuttleId: string): Promise { return Promise.resolve(null); }