1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-18 13:48:58 +02: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 { Db } from '../../db/db';
import type { Logger, LogProvider } from '../../logger'; import type { Logger, LogProvider } from '../../logger';
import type { 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( async getTrafficDataUsageForPeriod(
period: string, period: string,
): Promise<IStatTrafficUsage[]> { ): Promise<IStatTrafficUsage[]> {
const rows = await this.db<IStatTrafficUsage>(TABLE).whereRaw( const month = new Date(period);
`to_char(day, 'YYYY-MM') = ?`, return this.getDailyTrafficDataUsageForPeriod(
[period], startOfMonth(month),
endOfMonth(month),
); );
return rows.map(mapRow);
} }
async getTrafficDataForMonthRange( async getTrafficDataForMonthRange(