@@ -92,6 +92,8 @@ function generateImpressionOperationId(userId: string, impUrl: string): string {
9292const bodySchema = z . object ( {
9393 // Only impUrl needed - we look up the ad data from our database
9494 impUrl : z . url ( ) ,
95+ // Mode to determine if credits should be granted (FREE mode gets no credits)
96+ mode : z . string ( ) . optional ( ) ,
9597} )
9698
9799export async function postAdImpression ( params : {
@@ -115,6 +117,7 @@ export async function postAdImpression(params: {
115117
116118 // Parse and validate request body
117119 let impUrl : string
120+ let mode : string | undefined
118121 try {
119122 const json = await req . json ( )
120123 const parsed = bodySchema . safeParse ( json )
@@ -125,6 +128,7 @@ export async function postAdImpression(params: {
125128 )
126129 }
127130 impUrl = parsed . data . impUrl
131+ mode = parsed . data . mode
128132 } catch {
129133 return NextResponse . json (
130134 { error : 'Invalid JSON in request body' } ,
@@ -230,9 +234,9 @@ export async function postAdImpression(params: {
230234 Math . floor ( userShareDollars * 100 ) ,
231235 )
232236
233- // Grant credits if any
234237 let creditsGranted = 0
235- if ( creditsToGrant > 0 ) {
238+ // FREE mode should not grant any credits
239+ if ( mode !== 'FREE' && creditsToGrant > 0 ) {
236240 try {
237241 await processAndGrantCredit ( {
238242 userId,
@@ -282,7 +286,7 @@ export async function postAdImpression(params: {
282286 }
283287 }
284288
285- // Update the ad_impression record with impression details
289+ // Update the ad_impression record with impression details (for ALL modes)
286290 try {
287291 await db
288292 . update ( schema . adImpression )
@@ -294,7 +298,7 @@ export async function postAdImpression(params: {
294298 . where ( eq ( schema . adImpression . id , adRecord . id ) )
295299
296300 logger . info (
297- { userId, impUrl, creditsGranted } ,
301+ { userId, impUrl, creditsGranted, creditsToGrant } ,
298302 '[ads] Updated ad impression record' ,
299303 )
300304 } catch ( error ) {
0 commit comments