feat: add CRUD forms with Server Actions for establishments, users, classes, students
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/lib/auth-config";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function deleteClass(formData: FormData) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user) redirect("/login");
|
||||
if (!session.user.establishmentId && session.user.role !== "superadmin") redirect("/dashboard");
|
||||
|
||||
const id = formData.get("id") as string;
|
||||
if (!id) return;
|
||||
|
||||
const establishmentId = session.user.establishmentId;
|
||||
await prisma.class.deleteMany({
|
||||
where: { id, ...(establishmentId ? { establishmentId } : {}) },
|
||||
});
|
||||
|
||||
redirect("/dashboard/classes");
|
||||
}
|
||||
Reference in New Issue
Block a user