mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Add code to mark shuttle at a stop (Redis set)
This commit is contained in:
@@ -84,6 +84,11 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
|
||||
return `shuttle:eta:historical:${routeId}:${fromStopId}:${toStopId}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a set storing the shuttles that are currently at a stop.
|
||||
*/
|
||||
private readonly shuttleIsAtStopKey = "shuttle:atstop";
|
||||
|
||||
// Helper methods for converting entities to Redis hashes
|
||||
private createRedisHashFromStop = (stop: IStop): Record<string, string> => ({
|
||||
id: stop.id,
|
||||
@@ -409,10 +414,19 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
|
||||
lastStopArrival: lastStop,
|
||||
willArriveAt: shuttleArrival,
|
||||
});
|
||||
await this.markShuttleAsAtStop(shuttleArrival.shuttleId);
|
||||
await this.updateShuttleLastStopArrival(shuttleArrival);
|
||||
}
|
||||
}
|
||||
|
||||
private async markShuttleAsAtStop(shuttleId: string) {
|
||||
await this.redisClient.sAdd(this.shuttleIsAtStopKey, shuttleId);
|
||||
}
|
||||
|
||||
private async checkIfShuttleIsAtStop(shuttleId: string) {
|
||||
return await this.redisClient.sIsMember(this.shuttleIsAtStopKey, shuttleId);
|
||||
}
|
||||
|
||||
public async getAverageTravelTimeSeconds(
|
||||
{ routeId, fromStopId, toStopId }: ShuttleTravelTimeDataIdentifier,
|
||||
{ from, to }: ShuttleTravelTimeDateFilterArguments,
|
||||
|
||||
Reference in New Issue
Block a user