advance
This commit is contained in:
42
app/(protected)/teacher/courses/[slug]/edit/page.tsx
Normal file → Executable file
42
app/(protected)/teacher/courses/[slug]/edit/page.tsx
Normal file → Executable 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} />;
|
||||
}
|
||||
Reference in New Issue
Block a user