mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Restrict stop arrival event to only next stop after shuttle's last stop, if last stop exists
This commit is contained in:
@@ -445,18 +445,42 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the stop that the shuttle is currently at, if it exists.
|
||||||
|
*
|
||||||
|
* If the shuttle has a "last stop", it will only return the stop
|
||||||
|
* directly after the last stop. Otherwise, it may return any stop that
|
||||||
|
* is on the shuttle's route.
|
||||||
|
*
|
||||||
|
* @param shuttle
|
||||||
|
* @param delta
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
public async getArrivedStopIfExists(
|
public async getArrivedStopIfExists(
|
||||||
shuttle: IShuttle,
|
shuttle: IShuttle,
|
||||||
delta = 0.001,
|
delta = 0.001,
|
||||||
): Promise<IStop | undefined> {
|
): Promise<IStop | undefined> {
|
||||||
const orderedStops = await this.getOrderedStopsByRouteId(shuttle.routeId);
|
const lastStop = await this.getShuttleLastStopArrival(shuttle.id);
|
||||||
|
if (lastStop) {
|
||||||
|
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, delta)) {
|
||||||
|
return stopAfter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const orderedStops = await this.getOrderedStopsByRouteId(shuttle.routeId);
|
||||||
|
|
||||||
for (const orderedStop of orderedStops) {
|
for (const orderedStop of orderedStops) {
|
||||||
const stop = await this.getStopById(orderedStop.stopId);
|
const stop = await this.getStopById(orderedStop.stopId);
|
||||||
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, delta)) {
|
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, delta)) {
|
||||||
return stop;
|
return stop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user