81 lines
2.1 KiB
TypeScript
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" };
|
|
}
|
|
}
|