From ef20117f3c523866838890595c9b3a812a802ed0 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Mon, 10 Nov 2025 18:21:55 -0800 Subject: [PATCH] Modify getShuttleLastStopArrival to use shuttle ID --- src/repositories/shuttle/RedisShuttleRepository.ts | 8 ++++---- .../shuttle/__tests__/RedisShuttleRepository.test.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/repositories/shuttle/RedisShuttleRepository.ts b/src/repositories/shuttle/RedisShuttleRepository.ts index f00819e..8d20e9c 100644 --- a/src/repositories/shuttle/RedisShuttleRepository.ts +++ b/src/repositories/shuttle/RedisShuttleRepository.ts @@ -440,7 +440,7 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette ) { const oneWeekAgo = new Date(referenceCurrentTime.getTime() - (60 * 60 * 24 * 7 * 1000)) - const lastStopArrival = await this.getShuttleLastStopArrival(shuttle) + const lastStopArrival = await this.getShuttleLastStopArrival(shuttle.id) if (lastStopArrival == undefined) return; const lastOrderedStop = await this.getOrderedStopByRouteAndStopId(shuttle.routeId, lastStopArrival.stopId); @@ -476,7 +476,7 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette const arrivedStop = await this.getArrivedStopIfExists(shuttle); if (arrivedStop != undefined) { - const lastStopTimestamp = await this.getShuttleLastStopArrival(shuttle) + const lastStopTimestamp = await this.getShuttleLastStopArrival(shuttle.id) if (lastStopTimestamp != undefined) { const routeId = shuttle.routeId; const fromStopId = lastStopTimestamp.stopId; @@ -612,8 +612,8 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette return undefined; } - public async getShuttleLastStopArrival(shuttle: IShuttle): Promise { - const key = this.createShuttleLastStopKey(shuttle.id); + public async getShuttleLastStopArrival(shuttleId: string): Promise { + const key = this.createShuttleLastStopKey(shuttleId); const data = await this.redisClient.hGetAll(key); if (Object.keys(data).length === 0) { diff --git a/src/repositories/shuttle/__tests__/RedisShuttleRepository.test.ts b/src/repositories/shuttle/__tests__/RedisShuttleRepository.test.ts index 834870c..b99a5cb 100644 --- a/src/repositories/shuttle/__tests__/RedisShuttleRepository.test.ts +++ b/src/repositories/shuttle/__tests__/RedisShuttleRepository.test.ts @@ -90,7 +90,7 @@ describe("RedisShuttleRepository", () => { }; await repository.addOrUpdateShuttle(shuttle); - const lastStop = await repository.getShuttleLastStopArrival(shuttle); + const lastStop = await repository.getShuttleLastStopArrival(shuttle.id); expect(lastStop?.stopId).toEqual(stop2.id) }); @@ -213,7 +213,7 @@ describe("RedisShuttleRepository", () => { }; await repository.updateShuttleLastStopArrival(shuttle, stopArrival); - const result = await repository.getShuttleLastStopArrival(shuttle); + const result = await repository.getShuttleLastStopArrival(shuttle.id); expect(result).toBeDefined(); expect(result?.stopId).toBe(stopArrival.stopId); @@ -224,7 +224,7 @@ describe("RedisShuttleRepository", () => { const mockShuttles = generateMockShuttles(); const shuttle = mockShuttles[0]; - const result = await repository.getShuttleLastStopArrival(shuttle); + const result = await repository.getShuttleLastStopArrival(shuttle.id); expect(result).toBeUndefined(); }); @@ -246,7 +246,7 @@ describe("RedisShuttleRepository", () => { await repository.updateShuttleLastStopArrival(shuttle, firstArrival); await repository.updateShuttleLastStopArrival(shuttle, secondArrival); - const result = await repository.getShuttleLastStopArrival(shuttle); + const result = await repository.getShuttleLastStopArrival(shuttle.id); expect(result).toBeDefined(); expect(result?.stopId).toBe(secondArrival.stopId);