mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
Implement the events
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user