* Check if a user already owns an organization
(userId: string)
| 32 | * Check if a user already owns an organization |
| 33 | */ |
| 34 | async 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 | |
| 54 | export async function createOrganizationForTeamPlan( |
| 55 | userId: string, |
no test coverage detected