Skip to content

Commit a06fefb

Browse files
improve plan update
1 parent 7c88761 commit a06fefb

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

packages/api/src/router/stripe/webhook.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
workspace,
1616
} from "@openstatus/db/src/schema";
1717

18-
import type { addons } from "@openstatus/db/src/schema/plan/schema";
1918
import {
2019
getLimits,
2120
updateAddonInLimits,
@@ -68,39 +67,18 @@ export const webhookRouter = createTRPCRouter({
6867
const oldPlan = ws.plan;
6968

7069
let detectedPlan: ReturnType<typeof getPlanFromPriceId> = undefined;
71-
const detectedFeatures: Array<{ feature: (typeof addons)[number] }> = [];
7270

7371
for (const item of subscription.items.data) {
7472
const plan = getPlanFromPriceId(item.price.id);
7573
if (plan) {
7674
detectedPlan = plan;
77-
continue;
75+
break;
7876
}
79-
80-
const feature = getFeatureFromPriceId(item.price.id);
81-
if (feature) {
82-
detectedFeatures.push(feature);
83-
continue;
84-
}
85-
86-
console.warn(`Unknown price ID in subscription: ${item.price.id}`);
8777
}
8878

89-
let finalLimits = detectedPlan
79+
const finalLimits = detectedPlan
9080
? getLimits(detectedPlan.plan)
91-
: { ...ws.limits };
92-
93-
for (const feature of detectedFeatures) {
94-
const currentValue = finalLimits[feature.feature];
95-
const newValue =
96-
typeof currentValue === "boolean"
97-
? true
98-
: typeof currentValue === "number"
99-
? currentValue + 1
100-
: currentValue;
101-
102-
finalLimits = updateAddonInLimits(finalLimits, feature.feature, newValue);
103-
}
81+
: ws.limits;
10482

10583
await opts.ctx.db
10684
.update(workspace)

0 commit comments

Comments
 (0)