Implement the events

This commit is contained in:
2025-11-11 18:34:17 -08:00
parent 5b1c5897fc
commit 992a2b6149

View File

@@ -1,6 +1,7 @@
import { ShuttleGetterSetterRepository } from "./ShuttleGetterSetterRepository";
import { IEta, IOrderedStop, IRoute, IShuttle, IStop, shuttleHasArrivedAtStop } from "../../entities/ShuttleRepositoryEntities";
import {
ShuttleRepositoryEvent,
ShuttleRepositoryEventListener,
ShuttleRepositoryEventName,
ShuttleRepositoryEventPayloads,
@@ -383,6 +384,8 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
const key = this.createShuttleKey(shuttle.id);
await this.redisClient.hSet(key, this.createRedisHashFromShuttle(shuttle));
this.emit(ShuttleRepositoryEvent.SHUTTLE_UPDATED, shuttle);
await this.updateLastStopArrival(shuttle, travelTimeTimestamp);
}
@@ -393,12 +396,13 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
const arrivedStop = await this.getArrivedStopIfExists(shuttle);
if (arrivedStop != undefined) {
// TODO: Implement the event
await this.updateShuttleLastStopArrival({
const shuttleArrival = {
stopId: arrivedStop.id,
timestamp: new Date(travelTimeTimestamp),
shuttleId: shuttle.id,
})
};
await this.updateShuttleLastStopArrival(shuttleArrival);
this.emit(ShuttleRepositoryEvent.SHUTTLE_ARRIVED_AT_STOP, shuttleArrival);
}
}
@@ -498,6 +502,7 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
if (shuttle) {
const key = this.createShuttleKey(shuttleId);
await this.redisClient.del(key);
this.emit(ShuttleRepositoryEvent.SHUTTLE_REMOVED, shuttle);
return shuttle;
}
return null;