1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

chore(1-3293): add new query for daily data that uses date ranges

This commit is contained in:
Thomas Heartman 2025-01-24 14:38:28 +01:00
parent 938f12908b
commit 6fe1d9f1a7
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78

View File

@ -1,3 +1,4 @@
import { endOfMonth, startOfMonth } from 'date-fns';
import type { Db } from '../../db/db';
import type { Logger, LogProvider } from '../../logger';
import type {
@ -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(