Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add org owner Pro plan helper

Richie McIlroyf7a31cc9ec9c
diff --git a/apps/web/lib/org-pro.ts b/apps/web/lib/org-pro.ts
new file mode 100644
index 000000000..14014cf25
--- /dev/null
+++ b/apps/web/lib/org-pro.ts
@@ -0,0 +1,27 @@
+import "server-only";
+
+import { db } from "@cap/database";
+import { organizations, users } from "@cap/database/schema";
+import { userIsPro } from "@cap/utils";
+import type { Organisation } from "@cap/web-domain";
+import { eq } from "drizzle-orm";
+
+/**
+ * Whether an organization's OWNER is on a Pro plan. Public collection links are
+ * an org-wide Pro entitlement: any manager can publish while the owner is Pro.
+ */
+export async function isOrganizationOwnerPro(
+ organizationId: Organisation.OrganisationId,
+): Promise<boolean> {
+ const [owner] = await db()
+ .select({
+ stripeSubscriptionStatus: users.stripeSubscriptionStatus,
+ thirdPartyStripeSubscriptionId: users.thirdPartyStripeSubscriptionId,
+ })
+ .from(organizations)
+ .innerJoin(users, eq(organizations.ownerId, users.id))
+ .where(eq(organizations.id, organizationId))
+ .limit(1);
+
+ return userIsPro(owner ?? null);
+}