33 lines
974 B
TypeScript
33 lines
974 B
TypeScript
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 });
|
|
}
|
|
}
|