( entityType: 'user' | 'organization', entityId: string, amount: number )
| 71 | } |
| 72 | |
| 73 | export async function addCredits( |
| 74 | entityType: 'user' | 'organization', |
| 75 | entityId: string, |
| 76 | amount: number |
| 77 | ): Promise<void> { |
| 78 | if (entityType === 'organization') { |
| 79 | await db |
| 80 | .update(organization) |
| 81 | .set({ creditBalance: sql`${organization.creditBalance} + ${amount}` }) |
| 82 | .where(eq(organization.id, entityId)) |
| 83 | |
| 84 | logger.info('Added credits to organization', { organizationId: entityId, amount }) |
| 85 | } else { |
| 86 | await db |
| 87 | .update(userStats) |
| 88 | .set({ creditBalance: sql`${userStats.creditBalance} + ${amount}` }) |
| 89 | .where(eq(userStats.userId, entityId)) |
| 90 | |
| 91 | logger.info('Added credits to user', { userId: entityId, amount }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | async function removeCredits( |
| 96 | entityType: 'user' | 'organization', |
no test coverage detected