From 8c341e91e0275c2817f4cf94de16ffb43e46a946 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Fri, 21 Nov 2025 10:56:48 -0800 Subject: [PATCH] Call getArrivedStopIfExists based on different parameter --- src/repositories/shuttle/RedisShuttleRepository.ts | 11 ++++++++++- .../shuttle/UnoptimizedInMemoryShuttleRepository.ts | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/repositories/shuttle/RedisShuttleRepository.ts b/src/repositories/shuttle/RedisShuttleRepository.ts index 6c0ccdc..1b4d952 100644 --- a/src/repositories/shuttle/RedisShuttleRepository.ts +++ b/src/repositories/shuttle/RedisShuttleRepository.ts @@ -369,7 +369,16 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt travelTimeTimestamp = Date.now(), ) { const isAtStop = await this.checkIfShuttleIsAtStop(shuttle.id); - const arrivedStop = await this.getArrivedStopIfExists(shuttle); + + let arrivedStop: IStop | undefined; + + if (isAtStop) { + // Allow retrieval of the same stop + // Will still return undefined when the shuttle leaves the stop + arrivedStop = await this.getArrivedStopIfExists(shuttle, false); + } else { + arrivedStop = await this.getArrivedStopIfExists(shuttle, true); + } // Will not fire *any* events if the same stop const lastStop = await this.getShuttleLastStopArrival(shuttle.id); diff --git a/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts b/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts index f6fbafa..5239099 100644 --- a/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts +++ b/src/repositories/shuttle/UnoptimizedInMemoryShuttleRepository.ts @@ -184,7 +184,17 @@ export class UnoptimizedInMemoryShuttleRepository travelTimeTimestamp = Date.now(), ) { const isAtStop = await this.checkIfShuttleIsAtStop(shuttle.id); - const arrivedStop = await this.getArrivedStopIfExists(shuttle); + + let arrivedStop: IStop | undefined; + + if (isAtStop) { + // Allow retrieval of the same stop + // Will still return undefined when the shuttle leaves the stop + arrivedStop = await this.getArrivedStopIfExists(shuttle, false); + } else { + arrivedStop = await this.getArrivedStopIfExists(shuttle, true); + } + // Will not fire *any* events if the same stop const lastStop = await this.getShuttleLastStopArrival(shuttle.id);