1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

chore(1-3293): update fake store

This commit is contained in:
Thomas Heartman 2025-01-24 15:37:22 +01:00
parent 1c3226ee52
commit b6bb7bcc9d
No known key found for this signature in database
GPG Key ID: BD1F880DAED1EE78

View File

@ -89,4 +89,41 @@ export class FakeTrafficDataUsageStore implements ITrafficDataUsageStore {
return Object.values(data);
}
async getDailyTrafficDataForPeriod(
from: Date,
to: Date,
): Promise<IStatTrafficUsage[]> {
return this.trafficData.filter(
(data) => data.day >= from && data.day <= to,
);
}
async getMonthlyTrafficDataForPeriod(
from: Date,
to: Date,
): Promise<IStatMonthlyTrafficUsage[]> {
const data: { [key: string]: IStatMonthlyTrafficUsage } =
this.trafficData
.filter((entry) => entry.day >= from && entry.day <= to)
.reduce((acc, entry) => {
const month = format(entry.day, 'yyyy-MM');
const key = `${month}-${entry.trafficGroup}-${entry.statusCodeSeries}`;
if (acc[key]) {
acc[key].count += entry.count;
} else {
acc[key] = {
month,
trafficGroup: entry.trafficGroup,
statusCodeSeries: entry.statusCodeSeries,
count: entry.count,
};
}
return acc;
}, {});
return Object.values(data);
}
}