feat: fix quiz scoring to use Choice model correctness, add YouTube video support to lesson content, and include show_answers_after_completion in quiz data

Update quiz attempt detail scoring to determine correctness from Choice.is_correct instead of StudentAnswer.is_correct and calculate earned score based on correctness. Add YouTube video support to getLessonContent endpoint by checking LessonAttachment for YouTube videos (mime_type 'video/youtube') and building YouTube URLs from video IDs. Ad
This commit is contained in:
JakkrapartXD 2026-02-04 14:19:17 +07:00
parent 827b016114
commit 7e8c8e2532
3 changed files with 36 additions and 11 deletions

View file

@ -905,14 +905,19 @@ export class CoursesInstructorService {
const selectedChoiceId = studentAnswer?.choice_id || null;
const selectedChoice = selectedChoiceId ? question.choices.find(c => c.id === selectedChoiceId) : null;
// Check if selected choice is correct from Choice model
const isCorrect = selectedChoice?.is_correct || false;
// Score is question.score if correct, otherwise 0
const earnedScore = isCorrect ? question.score : 0;
return {
question_id: question.id,
sort_order: question.sort_order,
question_text: question.question as { th: string; en: string },
selected_choice_id: selectedChoiceId,
selected_choice_text: selectedChoice ? selectedChoice.text as { th: string; en: string } : null,
is_correct: studentAnswer?.is_correct || false,
score: studentAnswer?.score || 0,
is_correct: isCorrect,
score: earnedScore,
question_score: question.score,
};
});