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