MCPcopy Index your code
hub / github.com/simstudioai/sim / getCreditBalanceForEntity

Function getCreditBalanceForEntity

apps/sim/lib/billing/credits/balance.ts:30–50  ·  view source on GitHub ↗
(
  entityType: 'user' | 'organization',
  entityId: string,
  executor: DbClient = db
)

Source from the content-addressed store, hash-verified

28 * org owner as a user-id proxy.
29 */
30export async function getCreditBalanceForEntity(
31 entityType: 'user' | 'organization',
32 entityId: string,
33 executor: DbClient = db
34): Promise<number> {
35 if (entityType === 'organization') {
36 const rows = await executor
37 .select({ creditBalance: organization.creditBalance })
38 .from(organization)
39 .where(eq(organization.id, entityId))
40 .limit(1)
41 return rows.length > 0 ? toNumber(toDecimal(rows[0].creditBalance)) : 0
42 }
43
44 const rows = await executor
45 .select({ creditBalance: userStats.creditBalance })
46 .from(userStats)
47 .where(eq(userStats.userId, entityId))
48 .limit(1)
49 return rows.length > 0 ? toNumber(toDecimal(rows[0].creditBalance)) : 0
50}
51
52export async function getCreditBalance(
53 userId: string,

Callers 2

getCreditBalanceFunction · 0.85

Calls 3

toNumberFunction · 0.90
toDecimalFunction · 0.90
eqFunction · 0.50

Tested by

no test coverage detected