( userId: string, executor: DbClient = db )
| 50 | } |
| 51 | |
| 52 | export async function getCreditBalance( |
| 53 | userId: string, |
| 54 | executor: DbClient = db |
| 55 | ): Promise<CreditBalanceInfo> { |
| 56 | const subscription = await getHighestPrioritySubscription(userId, { executor }) |
| 57 | |
| 58 | if (isOrgScopedSubscription(subscription, userId) && subscription) { |
| 59 | return { |
| 60 | balance: await getCreditBalanceForEntity('organization', subscription.referenceId, executor), |
| 61 | entityType: 'organization', |
| 62 | entityId: subscription.referenceId, |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return { |
| 67 | balance: await getCreditBalanceForEntity('user', userId, executor), |
| 68 | entityType: 'user', |
| 69 | entityId: userId, |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | export async function addCredits( |
| 74 | entityType: 'user' | 'organization', |
no test coverage detected