@@ -206,14 +206,30 @@ export const getPlanInfo = async (
206206} ;
207207
208208/**
209- * Returns the Stripe subscription item quantity for the given user, derived
210- * from the latest customer.subscription.updated/created event in TransactionLog.
211- * Returns null when no subscription event exists yet (free plan, AppSumo, etc.).
209+ * Returns the extra-seat subscription quantity for the given user, derived
210+ * from the latest customer.subscription.updated/created event in TransactionLog
211+ * whose product is an extra-seat plan (maxSeatsPerWorkspace > 0, maxWorkspaces <= 1).
212+ *
213+ * Returns null when no matching event exists (free plan, no extra seats, etc.).
212214 */
213- export const getPaidSeats = async (
215+ export const getExtraPaidSeats = async (
214216 userId : string ,
215217 context : { postgrest : PostgrestContext }
216218) : Promise < number | null > => {
219+ const productResult = await context . postgrest . client
220+ . from ( "Product" )
221+ . select ( "id" )
222+ . eq ( "name" , "Seats" ) ;
223+
224+ if ( productResult . error ) {
225+ throw productResult . error ;
226+ }
227+
228+ const seatProductIds = ( productResult . data ?? [ ] ) . map ( ( p ) => p . id ) ;
229+ if ( seatProductIds . length === 0 ) {
230+ return null ;
231+ }
232+
217233 const result = await context . postgrest . client
218234 . from ( "TransactionLog" )
219235 . select ( "eventData" )
@@ -222,6 +238,7 @@ export const getPaidSeats = async (
222238 "customer.subscription.updated" ,
223239 "customer.subscription.created" ,
224240 ] )
241+ . in ( "productId" , seatProductIds )
225242 . order ( "eventCreated" , { ascending : false } )
226243 . limit ( 1 )
227244 . maybeSingle ( ) ;
0 commit comments