Implement getShuttleLastStopArrival and updateShuttleLastStopArrival

This commit is contained in:
2025-11-10 15:36:33 -08:00
parent 2a80a049bd
commit cba91dae55
2 changed files with 62 additions and 8 deletions

View File

@@ -105,6 +105,7 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette
private createShuttleKey = (shuttleId: string) => `shuttle:shuttle:${shuttleId}`;
private createEtaKey = (shuttleId: string, stopId: string) => `shuttle:eta:${shuttleId}:${stopId}`;
private createOrderedStopKey = (routeId: string, stopId: string) => `shuttle:orderedstop:${routeId}:${stopId}`;
private createShuttleLastStopKey = (shuttleId: string) => `shuttle:laststop:${shuttleId}`;
// Helper methods for converting entities to Redis hashes
private createRedisHashFromStop = (stop: IStop): Record<string, string> => ({
@@ -453,13 +454,25 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette
}
public async getShuttleLastStopArrival(shuttle: IShuttle): Promise<ShuttleStopArrival | undefined> {
// Get the *time* of the most recent time series entry for the key
throw Error("not implemented");
const key = this.createShuttleLastStopKey(shuttle.id);
const data = await this.redisClient.hGetAll(key);
if (Object.keys(data).length === 0) {
return undefined;
}
return {
stopId: data.stopId,
timestamp: new Date(data.timestamp),
};
}
public async updateShuttleLastStopArrival(shuttle: IShuttle, lastStopArrival: ShuttleStopArrival) {
// Key: shuttleId:stopId:
// Value: just a marker (no numerical value)
const key = this.createShuttleLastStopKey(shuttle.id);
await this.redisClient.hSet(key, {
stopId: lastStopArrival.stopId,
timestamp: lastStopArrival.timestamp.toISOString(),
});
}
public async addOrUpdateStop(stop: IStop): Promise<void> {