( userId: User.UserId, organizationId: Organisation.OrganisationId, )
| 19 | }; |
| 20 | |
| 21 | export async function getOrganizationAccess( |
| 22 | userId: User.UserId, |
| 23 | organizationId: Organisation.OrganisationId, |
| 24 | ): Promise<OrganizationAccess | null> { |
| 25 | const [organization] = await db() |
| 26 | .select({ |
| 27 | id: organizations.id, |
| 28 | ownerId: organizations.ownerId, |
| 29 | memberId: organizationMembers.id, |
| 30 | memberRole: organizationMembers.role, |
| 31 | }) |
| 32 | .from(organizations) |
| 33 | .leftJoin( |
| 34 | organizationMembers, |
| 35 | and( |
| 36 | eq(organizationMembers.organizationId, organizations.id), |
| 37 | eq(organizationMembers.userId, userId), |
| 38 | ), |
| 39 | ) |
| 40 | .where( |
| 41 | and( |
| 42 | eq(organizations.id, organizationId), |
| 43 | isNull(organizations.tombstoneAt), |
| 44 | or( |
| 45 | eq(organizations.ownerId, userId), |
| 46 | eq(organizationMembers.userId, userId), |
| 47 | ), |
| 48 | ), |
| 49 | ) |
| 50 | .limit(1); |
| 51 | |
| 52 | if (!organization) return null; |
| 53 | |
| 54 | const role = getEffectiveOrganizationRole({ |
| 55 | userId, |
| 56 | ownerId: organization.ownerId, |
| 57 | memberRole: organization.memberRole, |
| 58 | }); |
| 59 | |
| 60 | if (!role) return null; |
| 61 | |
| 62 | return { |
| 63 | id: organization.id, |
| 64 | ownerId: organization.ownerId, |
| 65 | memberId: organization.memberId, |
| 66 | role, |
| 67 | }; |
| 68 | } |
| 69 | |
| 70 | export async function requireOrganizationAccess( |
| 71 | userId: User.UserId, |
no test coverage detected