Look to the right org to test is subscribed

This commit is contained in:
Owen
2026-02-17 20:06:58 -08:00
parent 6661a76aa8
commit f591cf8601

View File

@@ -12,7 +12,8 @@
*/ */
import { build } from "@server/build"; import { build } from "@server/build";
import { db, customers, subscriptions } from "@server/db"; import { db, customers, subscriptions, orgs } from "@server/db";
import logger from "@server/logger";
import { Tier } from "@server/types/Tiers"; import { Tier } from "@server/types/Tiers";
import { eq, and, ne } from "drizzle-orm"; import { eq, and, ne } from "drizzle-orm";
@@ -27,14 +28,38 @@ export async function getOrgTierData(
} }
try { try {
const [org] = await db
.select()
.from(orgs)
.where(eq(orgs.orgId, orgId))
.limit(1);
if (!org) {
return { tier, active };
}
let orgIdToUse = org.orgId;
if (!org.isBillingOrg) {
if (!org.billingOrgId) {
logger.warn(
`Org ${orgId} is not a billing org and does not have a billingOrgId`
);
return { tier, active };
}
orgIdToUse = org.billingOrgId;
}
// Get customer for org // Get customer for org
const [customer] = await db const [customer] = await db
.select() .select()
.from(customers) .from(customers)
.where(eq(customers.orgId, orgId)) .where(eq(customers.orgId, orgIdToUse))
.limit(1); .limit(1);
if (customer) { if (!customer) {
return { tier, active };
}
// Query for active subscriptions that are not license type // Query for active subscriptions that are not license type
const [subscription] = await db const [subscription] = await db
.select() .select()
@@ -59,7 +84,6 @@ export async function getOrgTierData(
active = true; active = true;
} }
} }
}
} catch (error) { } catch (error) {
// If org not found or error occurs, return null tier and inactive // If org not found or error occurs, return null tier and inactive
// This is acceptable behavior as per the function signature // This is acceptable behavior as per the function signature