1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-17 13:46:47 +02:00

chore(1-3293): verify that data is end of day/start of day

This commit is contained in:
Thomas Heartman 2025-01-24 14:48:14 +01:00
parent 6079114217
commit 3ad10be1b2
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78

View File

@ -1,4 +1,10 @@
import { endOfMonth, startOfMonth, subMonths } from 'date-fns'; import {
endOfDay,
endOfMonth,
startOfDay,
startOfMonth,
subMonths,
} 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 {
@ -95,23 +101,12 @@ export class TrafficDataUsageStore implements ITrafficDataUsageStore {
to: Date, to: Date,
): Promise<IStatTrafficUsage[]> { ): Promise<IStatTrafficUsage[]> {
const rows = await this.db<IStatTrafficUsage>(TABLE) const rows = await this.db<IStatTrafficUsage>(TABLE)
.where('day', '>=', from) .where('day', '>=', startOfDay(from))
.andWhere('day', '<=', to); .andWhere('day', '<=', endOfDay(to));
return rows.map(mapRow); return rows.map(mapRow);
} }
// @deprecated: remove with flag `dataUsageMultiMonthView`
async getTrafficDataUsageForPeriod(
period: string,
): Promise<IStatTrafficUsage[]> {
const month = new Date(period);
return this.getDailyTrafficDataUsageForPeriod(
startOfMonth(month),
endOfMonth(month),
);
}
async getMonthlyTrafficDataUsageForPeriod( async getMonthlyTrafficDataUsageForPeriod(
from: Date, from: Date,
to: Date, to: Date,
@ -123,8 +118,8 @@ export class TrafficDataUsageStore implements ITrafficDataUsageStore {
this.db.raw(`to_char(day, 'YYYY-MM') AS month`), this.db.raw(`to_char(day, 'YYYY-MM') AS month`),
this.db.raw(`SUM(count) AS count`), this.db.raw(`SUM(count) AS count`),
) )
.where('day', '>=', from) .where('day', '>=', startOfDay(from))
.andWhere('day', '<=', to) .andWhere('day', '<=', endOfDay(to))
.groupBy([ .groupBy([
'traffic_group', 'traffic_group',
this.db.raw(`to_char(day, 'YYYY-MM')`), this.db.raw(`to_char(day, 'YYYY-MM')`),
@ -144,6 +139,17 @@ export class TrafficDataUsageStore implements ITrafficDataUsageStore {
); );
} }
async getTrafficDataUsageForPeriod(
period: string,
): Promise<IStatTrafficUsage[]> {
const month = new Date(period);
return this.getDailyTrafficDataUsageForPeriod(
startOfMonth(month),
endOfMonth(month),
);
}
// @deprecated: remove with flag `dataUsageMultiMonthView`
async getTrafficDataForMonthRange( async getTrafficDataForMonthRange(
monthsBack: number, monthsBack: number,
): Promise<IStatMonthlyTrafficUsage[]> { ): Promise<IStatMonthlyTrafficUsage[]> {