(
organizationId: string,
options: GetOrganizationSubscriptionOptions = {}
)
| 49 | * omit the executor (or pass `db`). |
| 50 | */ |
| 51 | export async function getOrganizationSubscription( |
| 52 | organizationId: string, |
| 53 | options: GetOrganizationSubscriptionOptions = {} |
| 54 | ) { |
| 55 | const { onError = 'return-null', executor = db } = options |
| 56 | try { |
| 57 | const orgSubs = await executor |
| 58 | .select() |
| 59 | .from(subscription) |
| 60 | .where( |
| 61 | and( |
| 62 | eq(subscription.referenceId, organizationId), |
| 63 | inArray(subscription.status, ENTITLED_SUBSCRIPTION_STATUSES) |
| 64 | ) |
| 65 | ) |
| 66 | .orderBy(desc(subscription.periodStart), desc(subscription.id)) |
| 67 | .limit(1) |
| 68 | |
| 69 | return orgSubs.length > 0 ? orgSubs[0] : null |
| 70 | } catch (error) { |
| 71 | logger.error('Error getting organization subscription', { error, organizationId }) |
| 72 | if (onError === 'throw') { |
| 73 | throw error |
| 74 | } |
| 75 | return null |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * BILLING MODEL: |
no test coverage detected