Skip to content

Commit 6c35464

Browse files
committed
make logger use new helper
1 parent 697f811 commit 6c35464

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

apps/sim/lib/billing/core/usage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { getEmailPreferences } from '@/lib/messaging/email/unsubscribe'
2222

2323
const logger = createLogger('UsageManagement')
2424

25-
interface OrgUsageLimitResult {
25+
export interface OrgUsageLimitResult {
2626
limit: number
2727
minimum: number
2828
}
@@ -32,7 +32,7 @@ interface OrgUsageLimitResult {
3232
* - Enterprise: Uses orgUsageLimit directly (fixed pricing)
3333
* - Team: Uses orgUsageLimit but never below seats × basePrice
3434
*/
35-
async function getOrgUsageLimit(
35+
export async function getOrgUsageLimit(
3636
organizationId: string,
3737
plan: string,
3838
seats: number | null

apps/sim/lib/logs/execution/logger.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { db } from '@sim/db'
22
import {
33
member,
4-
organization,
54
userStats,
65
user as userTable,
76
workflow,
@@ -10,7 +9,11 @@ import {
109
import { eq, sql } from 'drizzle-orm'
1110
import { v4 as uuidv4 } from 'uuid'
1211
import { getHighestPrioritySubscription } from '@/lib/billing/core/subscription'
13-
import { checkUsageStatus, maybeSendUsageThresholdEmail } from '@/lib/billing/core/usage'
12+
import {
13+
checkUsageStatus,
14+
getOrgUsageLimit,
15+
maybeSendUsageThresholdEmail,
16+
} from '@/lib/billing/core/usage'
1417
import { checkAndBillOverageThreshold } from '@/lib/billing/threshold-billing'
1518
import { isBillingEnabled } from '@/lib/core/config/environment'
1619
import { redactApiKeys } from '@/lib/core/security/redaction'
@@ -386,29 +389,8 @@ export class ExecutionLogger implements IExecutionLoggerService {
386389
limit,
387390
})
388391
} else if (sub?.referenceId) {
389-
// Fetch org usage limit
390-
const orgRows = await db
391-
.select({ orgUsageLimit: organization.orgUsageLimit })
392-
.from(organization)
393-
.where(eq(organization.id, sub.referenceId))
394-
.limit(1)
395-
396-
const configured =
397-
orgRows.length > 0 && orgRows[0].orgUsageLimit
398-
? Number.parseFloat(orgRows[0].orgUsageLimit)
399-
: null
400-
401-
let orgLimit: number
402-
if (sub.plan === 'enterprise') {
403-
// Enterprise: Use configured limit directly (no per-seat minimum)
404-
orgLimit = configured ?? 0
405-
} else {
406-
// Team: Use configured limit but never below seats × basePrice
407-
const { getPlanPricing } = await import('@/lib/billing/core/billing')
408-
const { basePrice } = getPlanPricing(sub.plan)
409-
const minimum = (sub.seats || 1) * basePrice
410-
orgLimit = configured !== null ? Math.max(configured, minimum) : minimum
411-
}
392+
// Get org usage limit using shared helper
393+
const { limit: orgLimit } = await getOrgUsageLimit(sub.referenceId, sub.plan, sub.seats)
412394

413395
const [{ sum: orgUsageBefore }] = await db
414396
.select({ sum: sql`COALESCE(SUM(${userStats.currentPeriodCost}), 0)` })

0 commit comments

Comments
 (0)