@@ -3,7 +3,6 @@ import { userStats } from '@sim/db/schema'
33import { eq , sql } from 'drizzle-orm'
44import { type NextRequest , NextResponse } from 'next/server'
55import { z } from 'zod'
6- import { deductFromCredits } from '@/lib/billing/credits/balance'
76import { checkAndBillOverageThreshold } from '@/lib/billing/threshold-billing'
87import { checkInternalApiKey } from '@/lib/copilot/utils'
98import { isBillingEnabled } from '@/lib/core/config/environment'
@@ -92,17 +91,11 @@ export async function POST(req: NextRequest) {
9291 return NextResponse . json ( { error : 'User stats record not found' } , { status : 500 } )
9392 }
9493
95- const { creditsUsed, overflow } = await deductFromCredits ( userId , cost )
96- if ( creditsUsed > 0 ) {
97- logger . info ( `[${ requestId } ] Deducted cost from credits` , { userId, creditsUsed, overflow } )
98- }
99- const costToStore = overflow
100-
10194 const updateFields = {
102- totalCost : sql `total_cost + ${ costToStore } ` ,
103- currentPeriodCost : sql `current_period_cost + ${ costToStore } ` ,
104- totalCopilotCost : sql `total_copilot_cost + ${ costToStore } ` ,
105- currentPeriodCopilotCost : sql `current_period_copilot_cost + ${ costToStore } ` ,
95+ totalCost : sql `total_cost + ${ cost } ` ,
96+ currentPeriodCost : sql `current_period_cost + ${ cost } ` ,
97+ totalCopilotCost : sql `total_copilot_cost + ${ cost } ` ,
98+ currentPeriodCopilotCost : sql `current_period_copilot_cost + ${ cost } ` ,
10699 totalCopilotCalls : sql `total_copilot_calls + 1` ,
107100 lastActive : new Date ( ) ,
108101 }
0 commit comments