Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: reset exceeded at when upgrading account

Carl-Gerhard Lindesvärdc9cf0274afe9
diff --git a/apps/api/src/controllers/webhook.controller.ts b/apps/api/src/controllers/webhook.controller.ts
index b164c9c3e..ccd447a2d 100644
--- a/apps/api/src/controllers/webhook.controller.ts
+++ b/apps/api/src/controllers/webhook.controller.ts
@@ -169,6 +169,11 @@ export async function polarWebhook(
.parse(event.data.metadata);
const product = await getProduct(event.data.productId);
+ const organization = await db.organization.findUniqueOrThrow({
+ where: {
+ id: metadata.organizationId,
+ },
+ });
const eventsLimit = product.metadata?.eventsLimit;
const subscriptionPeriodEventsLimit =
typeof eventsLimit === 'number' ? eventsLimit : undefined;
@@ -216,6 +221,13 @@ export async function polarWebhook(
subscriptionCreatedByUserId: metadata.userId,
subscriptionInterval: event.data.recurringInterval,
subscriptionPeriodEventsLimit,
+ subscriptionPeriodEventsCountExceededAt:
+ subscriptionPeriodEventsLimit &&
+ organization.subscriptionPeriodEventsCountExceededAt &&
+ organization.subscriptionPeriodEventsLimit <
+ subscriptionPeriodEventsLimit
+ ? null
+ : undefined,
},
});