MCPcopy Index your code
hub / github.com/simstudioai/sim / getUserOwnedOrganization

Function getUserOwnedOrganization

apps/sim/lib/billing/organization.ts:34–52  ·  view source on GitHub ↗

* Check if a user already owns an organization

(userId: string)

Source from the content-addressed store, hash-verified

32 * Check if a user already owns an organization
33 */
34async function getUserOwnedOrganization(userId: string): Promise<string | null> {
35 const existingMemberships = await db
36 .select({ organizationId: member.organizationId })
37 .from(member)
38 .where(and(eq(member.userId, userId), eq(member.role, 'owner')))
39 .limit(1)
40
41 if (existingMemberships.length > 0) {
42 const [existingOrg] = await db
43 .select({ id: organization.id })
44 .from(organization)
45 .where(eq(organization.id, existingMemberships[0].organizationId))
46 .limit(1)
47
48 return existingOrg?.id || null
49 }
50
51 return null
52}
53
54export async function createOrganizationForTeamPlan(
55 userId: string,

Callers 1

Calls 1

eqFunction · 0.50

Tested by

no test coverage detected