(
client: PoolClient,
orgId: string,
opts: { forUpdate?: boolean } = {},
)
| 273 | * caller needs to lock the organizations row as well. |
| 274 | */ |
| 275 | export async function readMembershipTierFromClient( |
| 276 | client: PoolClient, |
| 277 | orgId: string, |
| 278 | opts: { forUpdate?: boolean } = {}, |
| 279 | ): Promise<MembershipTier | null> { |
| 280 | const lockSuffix = opts.forUpdate ? ' FOR UPDATE' : ''; |
| 281 | const sql = `SELECT ${MEMBERSHIP_TIER_COLUMNS.join(', ')} FROM organizations WHERE workos_organization_id = $1${lockSuffix}`; |
| 282 | const result = await client.query<MembershipTierRow>(sql, [orgId]); |
| 283 | return resolveMembershipTier(result.rows[0] ?? null); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Infer membership tier from subscription amount and organization type. |
no test coverage detected