Update the method to accept a canReturnShuttleCurrentStop flag instead

This commit is contained in:
2025-11-21 11:07:47 -08:00
parent 8c341e91e0
commit 413443a162
4 changed files with 44 additions and 24 deletions

View File

@@ -188,11 +188,11 @@ export class UnoptimizedInMemoryShuttleRepository
let arrivedStop: IStop | undefined;
if (isAtStop) {
// Allow retrieval of the same stop
// Allow retrieval of the shuttle's current stop
// Will still return undefined when the shuttle leaves the stop
arrivedStop = await this.getArrivedStopIfExists(shuttle, false);
} else {
arrivedStop = await this.getArrivedStopIfExists(shuttle, true);
} else {
arrivedStop = await this.getArrivedStopIfExists(shuttle, false);
}
@@ -270,13 +270,21 @@ export class UnoptimizedInMemoryShuttleRepository
public async getArrivedStopIfExists(
shuttle: IShuttle,
returnNextStopOnly: boolean = false,
canReturnShuttleCurrentStop: boolean = false,
): Promise<IStop | undefined> {
const degreeDelta = this.shuttleStopArrivalDegreeDelta;
const lastStop = await this.getShuttleLastStopArrival(shuttle.id);
if (lastStop && returnNextStopOnly) {
const lastOrderedStop = await this.getOrderedStopByRouteAndStopId(shuttle.routeId, lastStop.stopId);
const lastStopArrival = await this.getShuttleLastStopArrival(shuttle.id);
if (lastStopArrival) {
// Return the shuttle's current stop depending on the flag
if (canReturnShuttleCurrentStop) {
const lastStop = await this.getStopById(lastStopArrival.stopId);
if (lastStop && shuttleHasArrivedAtStop(shuttle, lastStop, degreeDelta)) {
return lastStop;
}
}
const lastOrderedStop = await this.getOrderedStopByRouteAndStopId(shuttle.routeId, lastStopArrival.stopId);
const orderedStopAfter = lastOrderedStop?.nextStop;
if (orderedStopAfter) {
const stopAfter = await this.getStopById(orderedStopAfter.stopId);