(userId: string)
| 144 | * Creates userStats record with default free credits |
| 145 | */ |
| 146 | export async function handleNewUser(userId: string): Promise<void> { |
| 147 | try { |
| 148 | await db.insert(userStats).values({ |
| 149 | id: generateId(), |
| 150 | userId: userId, |
| 151 | currentUsageLimit: getFreeTierLimit().toString(), |
| 152 | usageLimitUpdatedAt: new Date(), |
| 153 | }) |
| 154 | |
| 155 | logger.info('User stats record created for new user', { userId }) |
| 156 | } catch (error) { |
| 157 | logger.error('Failed to create user stats record for new user', { |
| 158 | userId, |
| 159 | error, |
| 160 | }) |
| 161 | throw error |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Ensures a userStats record exists for a user. |
no test coverage detected