From 182587596c14a6fc1c8737df25f1b2dfb611e4e6 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Sat, 19 Jul 2025 12:15:41 -0400 Subject: [PATCH] Change properties to match GraphQL input and query result --- .../parking/InMemoryParkingRepository.ts | 10 +++++----- .../parking/ParkingGetterRepository.ts | 8 ++++---- .../parking/RedisParkingRepository.ts | 10 +++++----- .../ParkingRepositorySharedTests.test.ts | 16 ++++++++-------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/repositories/parking/InMemoryParkingRepository.ts b/src/repositories/parking/InMemoryParkingRepository.ts index 7ad25f6..0ca6ba2 100644 --- a/src/repositories/parking/InMemoryParkingRepository.ts +++ b/src/repositories/parking/InMemoryParkingRepository.ts @@ -110,10 +110,10 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository options: ParkingStructureCountOptions ): HistoricalParkingAverageQueryResult[] => { const results: HistoricalParkingAverageQueryResult[] = []; - const { startUnixEpochMs, endUnixEpochMs, intervalMs } = options; + const { from, to, intervalMs } = options; - let currentIntervalStart = startUnixEpochMs.getTime(); - const endTime = endUnixEpochMs.getTime(); + let currentIntervalStart = from.getTime(); + const endTime = to.getTime(); while (currentIntervalStart < endTime) { const currentIntervalEnd = Math.min(currentIntervalStart + intervalMs, endTime); @@ -149,8 +149,8 @@ export class InMemoryParkingRepository implements ParkingGetterSetterRepository const averageSpotsAvailable = totalSpotsAvailable / records.length; return { - fromUnixEpochMs: new Date(fromMs), - toUnixEpochMs: new Date(toMs), + from: new Date(fromMs), + to: new Date(toMs), averageSpotsAvailable }; }; diff --git a/src/repositories/parking/ParkingGetterRepository.ts b/src/repositories/parking/ParkingGetterRepository.ts index 315702c..3ce4998 100644 --- a/src/repositories/parking/ParkingGetterRepository.ts +++ b/src/repositories/parking/ParkingGetterRepository.ts @@ -1,14 +1,14 @@ import { IParkingStructure } from "../../entities/ParkingRepositoryEntities"; export interface ParkingStructureCountOptions { - startUnixEpochMs: Date; - endUnixEpochMs: Date; + from: Date; + to: Date; intervalMs: number; } export interface HistoricalParkingAverageQueryResult { - fromUnixEpochMs: Date; - toUnixEpochMs: Date; + from: Date; + to: Date; averageSpotsAvailable: number; } diff --git a/src/repositories/parking/RedisParkingRepository.ts b/src/repositories/parking/RedisParkingRepository.ts index e5f85fd..9747a69 100644 --- a/src/repositories/parking/RedisParkingRepository.ts +++ b/src/repositories/parking/RedisParkingRepository.ts @@ -160,11 +160,11 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki options: ParkingStructureCountOptions ): Promise => { const keys = this.createRedisKeys(id); - const { startUnixEpochMs, endUnixEpochMs, intervalMs } = options; + const { from, to, intervalMs } = options; const results: HistoricalParkingAverageQueryResult[] = []; - let currentIntervalStart = startUnixEpochMs.getTime(); - const endTime = endUnixEpochMs.getTime(); + let currentIntervalStart = from.getTime(); + const endTime = to.getTime(); while (currentIntervalStart < endTime) { const currentIntervalEnd = Math.min(currentIntervalStart + intervalMs, endTime); @@ -183,8 +183,8 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki if (aggregationResult && aggregationResult.length > 0) { const [, averageValue] = aggregationResult[0]; results.push({ - fromUnixEpochMs: new Date(currentIntervalStart), - toUnixEpochMs: new Date(currentIntervalEnd), + from: new Date(currentIntervalStart), + to: new Date(currentIntervalEnd), averageSpotsAvailable: parseFloat(averageValue) }); } diff --git a/test/repositories/ParkingRepositorySharedTests.test.ts b/test/repositories/ParkingRepositorySharedTests.test.ts index 1d97041..b92f8b5 100644 --- a/test/repositories/ParkingRepositorySharedTests.test.ts +++ b/test/repositories/ParkingRepositorySharedTests.test.ts @@ -152,8 +152,8 @@ describe.each(repositoryImplementations)('$name', (holder) => { describe("getHistoricalAveragesOfParkingStructureCounts", () => { it("should return empty array for non-existent structure or no data", async () => { const options: ParkingStructureCountOptions = { - startUnixEpochMs: new Date(1000), - endUnixEpochMs: new Date(2000), + from: new Date(1000), + to: new Date(2000), intervalMs: 500 }; @@ -183,8 +183,8 @@ describe.each(repositoryImplementations)('$name', (holder) => { const now = Date.now(); const options: ParkingStructureCountOptions = { - startUnixEpochMs: new Date(now - 10000), // Look back 10 seconds - endUnixEpochMs: new Date(now + 10000), // Look forward 10 seconds + from: new Date(now - 10000), // Look back 10 seconds + to: new Date(now + 10000), // Look forward 10 seconds intervalMs: 20000 // Single large interval }; @@ -193,10 +193,10 @@ describe.each(repositoryImplementations)('$name', (holder) => { // Should have at least some historical data expect(result.length).toEqual(1); if (result.length > 0) { - expect(result[0]).toHaveProperty('fromUnixEpochMs'); - expect(result[0]).toHaveProperty('toUnixEpochMs'); - expect(result[0].fromUnixEpochMs).toBeInstanceOf(Date); - expect(result[0].toUnixEpochMs).toBeInstanceOf(Date); + expect(result[0]).toHaveProperty('from'); + expect(result[0]).toHaveProperty('to'); + expect(result[0].from).toBeInstanceOf(Date); + expect(result[0].to).toBeInstanceOf(Date); expect(result[0]).toHaveProperty('averageSpotsAvailable'); expect(result[0].averageSpotsAvailable).toBeCloseTo(52.5); }