Add logic to fire the SHUTTLE_WILL_LEAVE_STOP event

This commit is contained in:
2025-11-18 21:06:10 -08:00
parent c8c5aa28c6
commit 83671e2b22
2 changed files with 52 additions and 14 deletions

View File

@@ -398,13 +398,24 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
shuttle: IShuttle,
travelTimeTimestamp = Date.now(),
) {
const isAtStop = await this.checkIfShuttleIsAtStop(shuttle.id);
const arrivedStop = await this.getArrivedStopIfExists(shuttle);
// Will not fire *any* events if the same stop
const lastStop = await this.getShuttleLastStopArrival(shuttle.id);
if (lastStop?.stopId === arrivedStop?.id) return;
if (isAtStop) {
if (lastStop) {
this.emit(ShuttleRepositoryEvent.SHUTTLE_WILL_LEAVE_STOP, {
stopArrivalThatShuttleIsLeaving: lastStop,
});
}
await this.markShuttleAsNotAtStop(shuttle.id);
}
if (arrivedStop) {
// stop if same stop
const lastStop = await this.getShuttleLastStopArrival(shuttle.id);
if (lastStop?.stopId === arrivedStop.id) return;
const shuttleArrival = {
stopId: arrivedStop.id,
timestamp: new Date(travelTimeTimestamp),