(
referenceId: string,
options: HasPaidSubscriptionOptions = {}
)
| 149 | * Fails closed by default: returns true on error to prevent duplicate creation. |
| 150 | */ |
| 151 | export async function hasPaidSubscription( |
| 152 | referenceId: string, |
| 153 | options: HasPaidSubscriptionOptions = {} |
| 154 | ): Promise<boolean> { |
| 155 | const { onError = 'assume-active' } = options |
| 156 | |
| 157 | try { |
| 158 | const [activeSub] = await db |
| 159 | .select({ id: subscription.id }) |
| 160 | .from(subscription) |
| 161 | .where( |
| 162 | and( |
| 163 | eq(subscription.referenceId, referenceId), |
| 164 | inArray(subscription.status, ENTITLED_SUBSCRIPTION_STATUSES) |
| 165 | ) |
| 166 | ) |
| 167 | .limit(1) |
| 168 | |
| 169 | return !!activeSub |
| 170 | } catch (error) { |
| 171 | logger.error('Error checking active subscription', { error, referenceId }) |
| 172 | |
| 173 | if (onError === 'throw') { |
| 174 | throw error |
| 175 | } |
| 176 | |
| 177 | return true |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | export async function getOrganizationIdForSubscriptionReference( |
| 182 | referenceId: string |
no test coverage detected