(organizationId: string)
| 88 | } |
| 89 | |
| 90 | export async function isOrganizationBillingBlocked(organizationId: string): Promise<boolean> { |
| 91 | const [owner] = await db |
| 92 | .select({ userId: member.userId }) |
| 93 | .from(member) |
| 94 | .where(and(eq(member.organizationId, organizationId), eq(member.role, 'owner'))) |
| 95 | .limit(1) |
| 96 | |
| 97 | if (!owner) { |
| 98 | logger.error( |
| 99 | 'Organization has no owner when checking billing-blocked state — data integrity issue', |
| 100 | { organizationId } |
| 101 | ) |
| 102 | return false |
| 103 | } |
| 104 | |
| 105 | const [ownerStats] = await db |
| 106 | .select({ blocked: userStats.billingBlocked }) |
| 107 | .from(userStats) |
| 108 | .where(eq(userStats.userId, owner.userId)) |
| 109 | .limit(1) |
| 110 | |
| 111 | return !!ownerStats?.blocked |
| 112 | } |
no test coverage detected