File tree Expand file tree Collapse file tree 1 file changed +3
-25
lines changed
packages/api/src/router/stripe Expand file tree Collapse file tree 1 file changed +3
-25
lines changed Original file line number Diff line number Diff 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" ;
1918import {
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 )
You can’t perform that action at this time.
0 commit comments