mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Update the method to accept a canReturnShuttleCurrentStop flag instead
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user