Files
2026-04-18 22:10:19 +02:00

50 lines
1.3 KiB
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,
context: { params: Promise<{ id: string }> }
): Promise<Response> {
try {
const { id } = await context.params;
if (!id) {
return NextResponse.json({ error: 'ID requis' }, { status: 400 });
}
// 1. Resolve actual Business UUID if id is a slug
const businessFound = await prisma.business.findFirst({
where: {
OR: [
{ id },
{ slug: id }
]
},
select: { id: true }
});
if (!businessFound) {
// If business not found in DB (might be mock), just return success but no update
return NextResponse.json({ success: true, message: 'Mock business, skipping view count' });
}
const businessId = businessFound.id;
// 2. Attempt to increment in DB
const business = await prisma.business.update({
where: { id: businessId },
data: {
viewCount: {
increment: 1,
},
},
});
return NextResponse.json({ success: true, viewCount: business.viewCount });
} catch (error) {
console.error('Error incrementing view count:', error);
return NextResponse.json({ success: false, error: 'Internal server error' }, { status: 500 });
}
}