feat: implement core platform features including business directory, admin dashboard, authentication, and API infrastructure
Some checks failed
Build and Push App / build (push) Failing after 16m2s
Some checks failed
Build and Push App / build (push) Failing after 16m2s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Force refresh for Next.js 16 params fix
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '../../../../../lib/prisma';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
@@ -13,10 +13,27 @@ export async function POST(
|
||||
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
|
||||
// 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 },
|
||||
where: { id: businessId },
|
||||
data: {
|
||||
viewCount: {
|
||||
increment: 1,
|
||||
@@ -26,8 +43,7 @@ export async function POST(
|
||||
|
||||
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 });
|
||||
return NextResponse.json({ success: false, error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user