| 1 | import { and, eq } from 'drizzle-orm' |
| 2 | import { memoize } |
| 3 | import { polarClient } |
| 4 | import { db } |
| 5 | import { members } |
| 6 | import { BillingCacheKeys } |
| 7 | |
| 8 | export const getOrganizationBillingStatus = |
| 9 | async (organizationId: |
| 10 | const [owner] |
| 11 | .select() |
| 12 | .from(members) |
| 13 | .where( |
| 14 | and( |
| 15 | eq(members.role |
| 16 | eq(members.organizationId |
| 17 | ) |
| 18 | ) |
| 19 | if (!owner) |
| 20 | return null |
| 21 | } |
| 22 | const data = |
| 23 | metadata: { referenceId: owner |
| 24 | }) |
| 25 | return data |
| 26 | }, |
| 27 | { |
| 28 | /// 1 hr |
| 29 | duration: 3600, |
| 30 | revalidateTags: (orgId) |
| 31 | BillingCacheKeys.getOrganizationBillingStatus(orgId |
| 32 | log: ['verbose'], |
| 33 | logid: 'Organization Billing Status', |
| 34 | } |
| 35 | ) |