65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
"use server";
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
import { revalidatePath } from "next/cache";
|
|
import { ContentStatus } from "@prisma/client";
|
|
|
|
export async function approveBlogPost(id: string) {
|
|
try {
|
|
await prisma.blogPost.update({
|
|
where: { id },
|
|
data: { status: ContentStatus.PUBLISHED }
|
|
});
|
|
revalidatePath("/actualites");
|
|
revalidatePath("/blog");
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error("Failed to approve blog post:", error);
|
|
return { success: false, error: "Erreur lors de l'approbation" };
|
|
}
|
|
}
|
|
|
|
export async function approveEvent(id: string) {
|
|
try {
|
|
await prisma.event.update({
|
|
where: { id },
|
|
data: { status: ContentStatus.PUBLISHED }
|
|
});
|
|
revalidatePath("/actualites");
|
|
revalidatePath("/evenements");
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error("Failed to approve event:", error);
|
|
return { success: false, error: "Erreur lors de l'approbation" };
|
|
}
|
|
}
|
|
|
|
export async function rejectBlogPost(id: string) {
|
|
try {
|
|
// We could delete or archive it. Let's archive it.
|
|
await prisma.blogPost.update({
|
|
where: { id },
|
|
data: { status: ContentStatus.ARCHIVED }
|
|
});
|
|
revalidatePath("/actualites");
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error("Failed to reject blog post:", error);
|
|
return { success: false, error: "Erreur lors du rejet" };
|
|
}
|
|
}
|
|
|
|
export async function rejectEvent(id: string) {
|
|
try {
|
|
await prisma.event.update({
|
|
where: { id },
|
|
data: { status: ContentStatus.ARCHIVED }
|
|
});
|
|
revalidatePath("/actualites");
|
|
return { success: true };
|
|
} catch (error) {
|
|
console.error("Failed to reject event:", error);
|
|
return { success: false, error: "Erreur lors du rejet" };
|
|
}
|
|
}
|