|
1 | 1 | import { db } from '@sim/db' |
2 | | -import { member, organization, subscription } from '@sim/db/schema' |
| 2 | +import { member, organization } from '@sim/db/schema' |
3 | 3 | import { createLogger } from '@sim/logger' |
4 | | -import { and, eq, inArray } from 'drizzle-orm' |
| 4 | +import { and, eq } from 'drizzle-orm' |
5 | 5 | import { type NextRequest, NextResponse } from 'next/server' |
6 | 6 | import { z } from 'zod' |
7 | 7 | import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log' |
8 | 8 | import { getSession } from '@/lib/auth' |
9 | | -import { checkEnterprisePlan, USABLE_SUBSCRIPTION_STATUSES } from '@/lib/billing/core/subscription' |
| 9 | +import { isOrganizationOnEnterprisePlan } from '@/lib/billing/core/subscription' |
10 | 10 | import type { OrganizationWhitelabelSettings } from '@/lib/branding/types' |
11 | 11 |
|
12 | 12 | const logger = createLogger('WhitelabelAPI') |
@@ -140,18 +140,9 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{ |
140 | 140 | ) |
141 | 141 | } |
142 | 142 |
|
143 | | - const [orgSubscription] = await db |
144 | | - .select() |
145 | | - .from(subscription) |
146 | | - .where( |
147 | | - and( |
148 | | - eq(subscription.referenceId, organizationId), |
149 | | - inArray(subscription.status, USABLE_SUBSCRIPTION_STATUSES) |
150 | | - ) |
151 | | - ) |
152 | | - .limit(1) |
| 143 | + const hasEnterprisePlan = await isOrganizationOnEnterprisePlan(organizationId) |
153 | 144 |
|
154 | | - if (!orgSubscription || !checkEnterprisePlan(orgSubscription)) { |
| 145 | + if (!hasEnterprisePlan) { |
155 | 146 | return NextResponse.json( |
156 | 147 | { error: 'Whitelabeling is available on Enterprise plans only' }, |
157 | 148 | { status: 403 } |
|
0 commit comments