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 @@ -13,7 +13,6 @@ import {
1313 workspace ,
1414} from "@openstatus/db/src/schema" ;
1515
16- import type { addons } from "@openstatus/db/src/schema/plan/schema" ;
1716import {
1817 getLimits ,
1918 updateAddonInLimits ,
@@ -66,39 +65,18 @@ export const webhookRouter = createTRPCRouter({
6665 const oldPlan = ws . plan ;
6766
6867 let detectedPlan : ReturnType < typeof getPlanFromPriceId > = undefined ;
69- const detectedFeatures : Array < { feature : ( typeof addons ) [ number ] } > = [ ] ;
7068
7169 for ( const item of subscription . items . data ) {
7270 const plan = getPlanFromPriceId ( item . price . id ) ;
7371 if ( plan ) {
7472 detectedPlan = plan ;
75- continue ;
73+ break ;
7674 }
77-
78- const feature = getFeatureFromPriceId ( item . price . id ) ;
79- if ( feature ) {
80- detectedFeatures . push ( feature ) ;
81- continue ;
82- }
83-
84- console . warn ( `Unknown price ID in subscription: ${ item . price . id } ` ) ;
8575 }
8676
87- let finalLimits = detectedPlan
77+ const finalLimits = detectedPlan
8878 ? getLimits ( detectedPlan . plan )
89- : { ...ws . limits } ;
90-
91- for ( const feature of detectedFeatures ) {
92- const currentValue = finalLimits [ feature . feature ] ;
93- const newValue =
94- typeof currentValue === "boolean"
95- ? true
96- : typeof currentValue === "number"
97- ? currentValue + 1
98- : currentValue ;
99-
100- finalLimits = updateAddonInLimits ( finalLimits , feature . feature , newValue ) ;
101- }
79+ : ws . limits ;
10280
10381 await opts . ctx . db
10482 . update ( workspace )
You can’t perform that action at this time.
0 commit comments