fix(dashboard): restrict data if trial ended

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-03-30 19:53:08 +02:00
parent ecda9a7d1b
commit 0f0bb13107
4 changed files with 40 additions and 15 deletions

View File

@@ -38,6 +38,7 @@ import {
getEventFiltersWhereClause,
getOrganizationByProjectId,
getOrganizationByProjectIdCached,
getOrganizationSubscriptionChartEndDate,
getProfiles,
} from '@openpanel/db';
import type {
@@ -509,23 +510,16 @@ export async function getChartSeries(input: IChartInputWithDates) {
}
export async function getChart(input: IChartInput) {
const organization = await getOrganizationByProjectIdCached(input.projectId);
if (!organization) {
throw TRPCNotFoundError(
`Organization not found by project id ${input.projectId} in getChart`,
);
}
const currentPeriod = getChartStartEndDate(input);
const previousPeriod = getChartPrevStartEndDate(currentPeriod);
// If the current period end date is after the subscription chart end date, we need to use the subscription chart end date
if (
organization.subscriptionChartEndDate &&
new Date(currentPeriod.endDate) > organization.subscriptionChartEndDate
) {
currentPeriod.endDate = organization.subscriptionChartEndDate.toISOString();
const endDate = await getOrganizationSubscriptionChartEndDate(
input.projectId,
currentPeriod.endDate,
);
if (endDate) {
currentPeriod.endDate = endDate;
}
const promises = [getChartSeries({ ...input, ...currentPeriod })];