Change properties to match GraphQL input and query result

This commit is contained in:
2025-07-19 12:15:41 -04:00
parent 8ee1f1522e
commit 182587596c
4 changed files with 22 additions and 22 deletions

View File

@@ -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
};
};

View File

@@ -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;
}

View File

@@ -160,11 +160,11 @@ export class RedisParkingRepository extends BaseRedisRepository implements Parki
options: ParkingStructureCountOptions
): Promise<HistoricalParkingAverageQueryResult[]> => {
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)
});
}

View File

@@ -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);
}