mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Update getArrivedStopIfExists method to take an argument returnNextStopOnly
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user