Files
afrov2/admin/src/app/actions/moderation.ts
streaper2 f1ea12792a
Some checks failed
Build and Push App / build (push) Failing after 47s
correction admin moderation
2026-04-18 22:41:52 +02:00

81 lines
2.1 KiB
TypeScript

"use server";
import { prisma } from '@/lib/prisma';
import { revalidatePath } from 'next/cache';
export async function getReports() {
return await prisma.messageReport.findMany({
include: {
message: {
include: {
sender: {
select: { id: true, name: true, email: true, isSuspended: true }
},
conversation: {
include: {
business: {
select: { id: true, name: true }
},
messages: {
orderBy: { createdAt: 'asc' },
include: {
sender: {
select: { id: true, name: true }
}
}
}
}
}
}
},
reporter: {
select: { id: true, name: true, email: true }
}
},
orderBy: {
createdAt: 'desc',
},
});
}
export async function updateReportStatus(id: string, status: 'RESOLVED' | 'DISMISSED') {
try {
await prisma.messageReport.update({
where: { id },
data: { status }
});
revalidatePath('/moderation');
return { success: true };
} catch (error) {
return { success: false, error: "Erreur lors de la mise à jour" };
}
}
export async function getPendingRatings() {
return await prisma.rating.findMany({
where: { status: 'PENDING' },
include: {
user: {
select: { id: true, name: true, email: true }
},
business: {
select: { id: true, name: true }
}
},
orderBy: { createdAt: 'desc' }
});
}
export async function updateRatingStatus(id: string, status: 'APPROVED' | 'REJECTED') {
try {
await prisma.rating.update({
where: { id },
data: { status }
});
revalidatePath('/moderation');
return { success: true };
} catch (error) {
return { success: false, error: "Erreur lors de la mise à jour de l'avis" };
}
}