feat: add admin dashboard and core API routes with Docker configuration
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { getAuthUser } from '@/lib/auth-utils';
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id: paramId } = await context.params;
|
||||
const userId = req.headers.get('x-user-id');
|
||||
const authUser = await getAuthUser(req);
|
||||
|
||||
if (!userId) {
|
||||
if (!authUser) {
|
||||
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 });
|
||||
}
|
||||
|
||||
const userId = authUser.id;
|
||||
|
||||
try {
|
||||
const { value, comment } = await req.json();
|
||||
|
||||
@@ -27,7 +30,7 @@ export async function POST(
|
||||
{ slug: paramId }
|
||||
]
|
||||
},
|
||||
select: { id: true }
|
||||
select: { id: true, ownerId: true }
|
||||
});
|
||||
|
||||
if (!business) {
|
||||
@@ -35,7 +38,7 @@ export async function POST(
|
||||
}
|
||||
|
||||
const businessId = business.id;
|
||||
const ownerId = (business as any).ownerId;
|
||||
const ownerId = business.ownerId;
|
||||
|
||||
// 2. Security: Don't allow owner to rate themselves
|
||||
if (userId === ownerId) {
|
||||
@@ -85,7 +88,7 @@ export async function POST(
|
||||
|
||||
// 3. Aggregate all ratings for this business
|
||||
const stats = await prisma.rating.aggregate({
|
||||
where: { businessId },
|
||||
where: { businessId, status: 'APPROVED' },
|
||||
_avg: { value: true },
|
||||
_count: { value: true }
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user