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