Update getArrivedStopIfExists method to take an argument returnNextStopOnly

This commit is contained in:
2025-11-21 10:51:38 -08:00
parent c2f1a67a70
commit 712e311006
4 changed files with 56 additions and 26 deletions

View File

@@ -260,16 +260,31 @@ export class UnoptimizedInMemoryShuttleRepository
public async getArrivedStopIfExists(
shuttle: IShuttle,
returnNextStopOnly: boolean = false,
): Promise<IStop | undefined> {
const delta = this.shuttleStopArrivalDegreeDelta;
const orderedStops = await this.getOrderedStopsByRouteId(shuttle.routeId);
const degreeDelta = this.shuttleStopArrivalDegreeDelta;
for (const orderedStop of orderedStops) {
const stop = await this.getStopById(orderedStop.stopId);
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, delta)) {
return stop;
const lastStop = await this.getShuttleLastStopArrival(shuttle.id);
if (lastStop && returnNextStopOnly) {
const lastOrderedStop = await this.getOrderedStopByRouteAndStopId(shuttle.routeId, lastStop.stopId);
const orderedStopAfter = lastOrderedStop?.nextStop;
if (orderedStopAfter) {
const stopAfter = await this.getStopById(orderedStopAfter.stopId);
if (stopAfter && shuttleHasArrivedAtStop(shuttle, stopAfter, degreeDelta)) {
return stopAfter;
}
}
} else {
const orderedStops = await this.getOrderedStopsByRouteId(shuttle.routeId);
for (const orderedStop of orderedStops) {
const stop = await this.getStopById(orderedStop.stopId);
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, degreeDelta)) {
return stop;
}
}
}
return undefined;
}