mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Implement getShuttleLastStopArrival and updateShuttleLastStopArrival
This commit is contained in:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user