Files
afrov2/app/api/businesses/[id]/view/route.ts
streaper2 fae94ed8b1
Some checks failed
Build and Push App / build (push) Failing after 21s
fix build
2026-04-15 22:18:13 +02:00

34 lines
1017 B
TypeScript

// Force refresh for Next.js 16 params fix
import { NextRequest, NextResponse } from 'next/server';
import prisma from '../../../../../lib/prisma';
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
if (!id) {
return NextResponse.json({ error: 'ID requis' }, { status: 400 });
}
// Attempt to increment in DB
// Note: We don't care about mock businesses here as they are static
const business = await prisma.business.update({
where: { id },
data: {
viewCount: {
increment: 1,
},
},
});
return NextResponse.json({ success: true, viewCount: business.viewCount });
} catch (error) {
// If business not found in DB (might be mock), just return success but no update
console.error('Error incrementing view count:', error);
return NextResponse.json({ success: false, error: 'Business not found or error' }, { status: 404 });
}
}