feat: add admin dashboard and core API routes with Docker configuration
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '../../../../../lib/prisma';
|
||||
import { getAuthUser } from '@/lib/auth-utils';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const authUser = await getAuthUser(request);
|
||||
if (!authUser) {
|
||||
return NextResponse.json({ error: 'Authentification requise' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
if (!id) {
|
||||
return NextResponse.json({ error: 'ID Business requis' }, { status: 400 });
|
||||
}
|
||||
|
||||
// Verify ownership or ADMIN role
|
||||
const business = await prisma.business.findUnique({
|
||||
where: { id },
|
||||
select: { id: true, ownerId: true }
|
||||
});
|
||||
|
||||
if (!business) {
|
||||
return NextResponse.json({ error: 'Entreprise non trouvée' }, { status: 404 });
|
||||
}
|
||||
|
||||
if (business.ownerId !== authUser.id && authUser.role !== 'ADMIN') {
|
||||
return NextResponse.json({ error: 'Accès non autorisé' }, { status: 403 });
|
||||
}
|
||||
|
||||
// 1. Get total views from AnalyticsEvent
|
||||
const totalViews = await prisma.analyticsEvent.count({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user