MVP
This commit is contained in:
@@ -8,6 +8,7 @@ import { ContentStatus, Prisma, ProficiencyLevel } from "@prisma/client";
|
||||
import {
|
||||
buildLessonDescriptionMeta,
|
||||
parseLessonDescriptionMeta,
|
||||
type LessonActivityMeta,
|
||||
type LessonContentType,
|
||||
} from "@/lib/courses/lessonContent";
|
||||
|
||||
@@ -186,9 +187,11 @@ export async function updateLesson(lessonId: string, data: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
videoUrl?: string;
|
||||
youtubeUrl?: string;
|
||||
youtubeUrl?: string | null;
|
||||
materialUrl?: string;
|
||||
contentType?: LessonContentType;
|
||||
lectureContent?: string;
|
||||
activity?: LessonActivityMeta | null;
|
||||
estimatedDurationMinutes?: number;
|
||||
isPreview?: boolean; // maps to DB field isFreePreview
|
||||
isPublished?: boolean; // optional: for later
|
||||
@@ -200,7 +203,7 @@ export async function updateLesson(lessonId: string, data: {
|
||||
const updateData: Prisma.LessonUpdateInput = { updatedAt: new Date() };
|
||||
if (data.title !== undefined) updateData.title = data.title;
|
||||
if (data.videoUrl !== undefined) updateData.videoUrl = data.videoUrl;
|
||||
if (data.youtubeUrl !== undefined) updateData.youtubeUrl = data.youtubeUrl;
|
||||
if (data.youtubeUrl !== undefined) updateData.youtubeUrl = data.youtubeUrl?.trim() || null;
|
||||
if (data.estimatedDurationMinutes !== undefined) {
|
||||
const minutes = Math.max(0, Math.round(data.estimatedDurationMinutes));
|
||||
updateData.estimatedDuration = minutes * 60;
|
||||
@@ -208,7 +211,11 @@ export async function updateLesson(lessonId: string, data: {
|
||||
if (data.isPreview !== undefined) updateData.isFreePreview = data.isPreview;
|
||||
|
||||
const shouldUpdateMeta =
|
||||
data.description !== undefined || data.contentType !== undefined || data.materialUrl !== undefined;
|
||||
data.description !== undefined ||
|
||||
data.contentType !== undefined ||
|
||||
data.materialUrl !== undefined ||
|
||||
data.lectureContent !== undefined ||
|
||||
data.activity !== undefined;
|
||||
|
||||
if (shouldUpdateMeta) {
|
||||
const lesson = await db.lesson.findUnique({
|
||||
@@ -221,7 +228,9 @@ export async function updateLesson(lessonId: string, data: {
|
||||
text: data.description ?? existingMeta.text,
|
||||
contentType: data.contentType ?? existingMeta.contentType,
|
||||
materialUrl: data.materialUrl ?? existingMeta.materialUrl,
|
||||
});
|
||||
lectureContent: data.lectureContent ?? existingMeta.lectureContent,
|
||||
activity: data.activity ?? existingMeta.activity,
|
||||
}) as Prisma.InputJsonValue;
|
||||
}
|
||||
|
||||
await db.lesson.update({
|
||||
@@ -300,7 +309,7 @@ export async function updateModuleTitle(moduleId: string, title: string) {
|
||||
}
|
||||
|
||||
// 2. CREATE LESSON
|
||||
export async function createLesson(moduleId: string) {
|
||||
export async function createLesson(moduleId: string, contentType: LessonContentType = "VIDEO") {
|
||||
const user = await requireTeacher();
|
||||
if (!user) return { success: false, error: "Unauthorized" };
|
||||
|
||||
@@ -318,9 +327,11 @@ export async function createLesson(moduleId: string) {
|
||||
data: {
|
||||
moduleId,
|
||||
title: "Nueva Lección",
|
||||
description: {
|
||||
contentType: "VIDEO",
|
||||
},
|
||||
description: buildLessonDescriptionMeta({
|
||||
text: "",
|
||||
contentType,
|
||||
lectureContent: "",
|
||||
}) as Prisma.InputJsonValue,
|
||||
orderIndex: newOrder,
|
||||
estimatedDuration: 0,
|
||||
version: 1,
|
||||
|
||||
Reference in New Issue
Block a user