Pass down the new arguments into the shuttle repositories

This commit is contained in:
2025-11-20 16:47:50 -08:00
parent 645fe1055b
commit a9db9b5d5c
3 changed files with 34 additions and 7 deletions

View File

@@ -10,8 +10,18 @@ import {
ShuttleTravelTimeDateFilterArguments
} from "./ShuttleGetterRepository";
import { BaseRedisRepository } from "../BaseRedisRepository";
import { RedisClientType } from "redis";
import createRedisClientForRepository from "../../helpers/createRedisClientForRepository";
export class RedisShuttleRepository extends BaseRedisRepository implements ShuttleGetterSetterRepository {
constructor(
redisClient: RedisClientType = createRedisClientForRepository(),
readonly shuttleStopArrivalDegreeDelta: number = 0.001,
readonly shuttleStopNearbyDegreeDelta: number = 0.003,
) {
super(redisClient);
}
get isReady() {
return this.redisClient.isReady;
}
@@ -481,20 +491,21 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
* is on the shuttle's route.
*
* @param shuttle
* @param delta
* @param degreeDelta
* @returns
*/
public async getArrivedStopIfExists(
shuttle: IShuttle,
delta = 0.001,
): Promise<IStop | undefined> {
const degreeDelta = this.shuttleStopArrivalDegreeDelta;
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)) {
if (stopAfter && shuttleHasArrivedAtStop(shuttle, stopAfter, degreeDelta)) {
return stopAfter;
}
}
@@ -503,7 +514,7 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
for (const orderedStop of orderedStops) {
const stop = await this.getStopById(orderedStop.stopId);
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, delta)) {
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, degreeDelta)) {
return stop;
}
}