43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
"use server";
|
|
|
|
import { prisma } from "@/lib/prisma";
|
|
import { revalidatePath } from "next/cache";
|
|
import { ContentStatus } from "@prisma/client";
|
|
|
|
export async function createEvent(data: {
|
|
title: string;
|
|
description: string;
|
|
date: string;
|
|
location: string;
|
|
thumbnailUrl: string;
|
|
link?: string;
|
|
tags?: string[];
|
|
}) {
|
|
try {
|
|
const slug = data.title
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/(^-|-$)/g, '');
|
|
|
|
const event = await prisma.event.create({
|
|
data: {
|
|
title: data.title,
|
|
description: data.description,
|
|
date: new Date(data.date),
|
|
location: data.location,
|
|
thumbnailUrl: data.thumbnailUrl,
|
|
link: data.link || null,
|
|
tags: data.tags || [],
|
|
status: 'PENDING' as ContentStatus, // Always pending for user submission
|
|
slug: `${slug}-${Math.random().toString(36).substring(2, 7)}`
|
|
}
|
|
});
|
|
|
|
revalidatePath("/evenements");
|
|
return { success: true, event };
|
|
} catch (error) {
|
|
console.error("Failed to create event:", error);
|
|
return { success: false, error: "Erreur lors de la création de l'événement" };
|
|
}
|
|
}
|