add quastion to api

This commit is contained in:
JakkrapartXD 2026-01-22 17:16:52 +07:00
parent dcf0385a87
commit 76f8ab120a
2 changed files with 37 additions and 3 deletions

View file

@ -283,14 +283,25 @@ export class CoursesStudentService {
throw new ForbiddenError('You are not enrolled in this course');
}
// Get lesson with attachments and quiz
// Get lesson with attachments and quiz (including questions and choices)
const lesson = await prisma.lesson.findUnique({
where: { id: lesson_id },
include: {
attachments: {
orderBy: { sort_order: 'asc' },
},
quiz: true,
quiz: {
include: {
questions: {
orderBy: { sort_order: 'asc' },
include: {
choices: {
orderBy: { sort_order: 'asc' },
},
},
},
},
},
chapter: {
include: {
lessons: {
@ -420,6 +431,18 @@ export class CoursesStudentService {
time_limit: lesson.quiz.time_limit,
shuffle_questions: lesson.quiz.shuffle_questions,
shuffle_choices: lesson.quiz.shuffle_choices,
questions: lesson.quiz.questions.map(q => ({
id: q.id,
question: q.question as { th: string; en: string },
question_type: q.question_type,
score: q.score,
sort_order: q.sort_order,
choices: q.choices.map(c => ({
id: c.id,
text: c.text as { th: string; en: string },
sort_order: c.sort_order,
})),
})),
} : null,
prev_lesson_id: prevLessonId,
next_lesson_id: nextLessonId,

View file

@ -150,7 +150,6 @@ export interface LessonContentData {
presigned_url: string | null; // Presigned URL for attachment
}[];
quiz?: {
id: number;
title: MultiLangText;
description: MultiLangText | null;
@ -158,6 +157,18 @@ export interface LessonContentData {
time_limit: number | null;
shuffle_questions: boolean;
shuffle_choices: boolean;
questions: {
id: number;
question: MultiLangText;
question_type: 'MULTIPLE_CHOICE' | 'TRUE_FALSE' | 'SHORT_ANSWER';
score: number;
sort_order: number;
choices: {
id: number;
text: MultiLangText;
sort_order: number;
}[];
}[];
} | null;
// Navigation
prev_lesson_id: number | null;