Files
streaper2 889e70bfc0
Some checks failed
Build and Push App / build (push) Failing after 21s
fix build
2026-04-15 22:40:04 +02:00

39 lines
1.2 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import prisma from '../../../../../lib/prisma'
// PATCH /api/admin/reports/[id] — Update report status
export async function PATCH(
request: NextRequest,
context: { params: Promise<{ id: string }> }
): Promise<Response> {
try {
const userId = request.headers.get('x-user-id')
const { id } = await context.params
const { status } = await request.json()
if (!userId) {
return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 })
}
// Check if user is admin
const user = await prisma.user.findUnique({
where: { id: userId },
select: { role: true }
})
if (!user || user.role !== 'ADMIN') {
return NextResponse.json({ error: 'Accès réservé aux administrateurs' }, { status: 403 })
}
const report = await prisma.messageReport.update({
where: { id },
data: { status }
})
return NextResponse.json(report)
} catch (error) {
console.error('PATCH /api/admin/reports/[id] error:', error)
return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 })
}
}