This commit is contained in:
Marcelo
2026-02-17 00:07:00 +00:00
parent b7a86a2d1c
commit be4ca2ed78
92 changed files with 6850 additions and 1188 deletions

42
app/(protected)/teacher/courses/[slug]/edit/page.tsx Normal file → Executable file
View File

@@ -1,13 +1,41 @@
import { db } from "@/lib/prisma";
import { requireTeacher } from "@/lib/auth/requireTeacher";
import { notFound, redirect } from "next/navigation";
import TeacherEditCourseForm from "@/components/teacher/TeacherEditCourseForm";
type TeacherEditCoursePageProps = {
params: Promise<{ slug: string }>;
};
export default async function CourseEditPage({ params }: { params: Promise<{ slug: string }> }) {
const user = await requireTeacher();
if (!user) redirect("/auth/login");
export default async function TeacherEditCoursePage({ params }: TeacherEditCoursePageProps) {
await requireTeacher();
const { slug } = await params;
return <TeacherEditCourseForm slug={slug} />;
}
// Fetch Course + Modules + Lessons
const course = await db.course.findUnique({
where: { slug: slug },
include: {
modules: {
orderBy: { orderIndex: "asc" },
include: {
lessons: {
orderBy: { orderIndex: "asc" },
},
},
},
},
});
if (!course) notFound();
// Security Check
if (course.authorId !== user.id && user.role !== "SUPER_ADMIN") {
return <div>No autorizado</div>;
}
// Transform Decimal to number for the UI component
const courseData = {
...course,
price: course.price.toNumber(),
};
return <TeacherEditCourseForm course={courseData} />;
}