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:
parent
938f12908b
commit
6fe1d9f1a7
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user