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:
49
app/api/businesses/[id]/rating/me/route.ts
Normal file
49
app/api/businesses/[id]/rating/me/route.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id: paramId } = await context.params;
|
||||
const userId = req.headers.get('x-user-id');
|
||||
|
||||
if (!userId) {
|
||||
return NextResponse.json({ rating: null });
|
||||
}
|
||||
|
||||
try {
|
||||
// Resolve actual Business UUID if paramId is a slug
|
||||
const business = await prisma.business.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{ id: paramId },
|
||||
{ slug: paramId }
|
||||
]
|
||||
},
|
||||
select: { id: true }
|
||||
});
|
||||
|
||||
if (!business) {
|
||||
return NextResponse.json({ rating: null });
|
||||
}
|
||||
|
||||
const rating = await prisma.rating.findUnique({
|
||||
where: {
|
||||
userId_businessId: {
|
||||
userId,
|
||||
businessId: business.id
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
rating: rating ? rating.value : null,
|
||||
status: rating ? rating.status : null,
|
||||
comment: rating ? rating.comment : null
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('Error fetching user rating:', error);
|
||||
return NextResponse.json({ error: 'Erreur lors de la récupération de votre note' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user