Skip to content

Commit

Permalink
chore(1-3293): add new query for daily data that uses date ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Jan 24, 2025
1 parent 938f129 commit 6fe1d9f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/lib/features/traffic-data-usage/traffic-data-usage-store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { endOfMonth, startOfMonth } from 'date-fns';
import type { Db } from '../../db/db';
import type { Logger, LogProvider } from '../../logger';
import type {
Expand Down Expand Up @@ -89,14 +90,26 @@ export class TrafficDataUsageStore implements ITrafficDataUsageStore {
});
}

async getDailyTrafficDataUsageForPeriod(
from: Date,
to: Date,
): Promise<IStatTrafficUsage[]> {
const rows = await this.db<IStatTrafficUsage>(TABLE)
.where('day', '>=', from)
.andWhere('day', '<=', to);

return rows.map(mapRow);
}

// @deprecated: remove with flag `dataUsageMultiMonthView`
async getTrafficDataUsageForPeriod(
period: string,
): Promise<IStatTrafficUsage[]> {
const rows = await this.db<IStatTrafficUsage>(TABLE).whereRaw(
`to_char(day, 'YYYY-MM') = ?`,
[period],
const month = new Date(period);
return this.getDailyTrafficDataUsageForPeriod(
startOfMonth(month),
endOfMonth(month),
);
return rows.map(mapRow);
}

async getTrafficDataForMonthRange(
Expand Down

0 comments on commit 6fe1d9f

Please sign in to comment.