Add lessons
This commit is contained in:
@@ -183,20 +183,20 @@ class LessonModule {
|
||||
/**
|
||||
* Get lesson content for rendering (without answers)
|
||||
*/
|
||||
getContent() {
|
||||
return {
|
||||
lessonKey: this.lessonKey,
|
||||
title: this.config.title,
|
||||
description: this.config.description,
|
||||
difficultyLevel: this.config.difficultyLevel,
|
||||
estimatedDuration: this.config.estimatedDuration,
|
||||
steps: this.config.steps.map(step => ({
|
||||
async getContent() {
|
||||
// Map steps and fetch interactive data for interactive steps
|
||||
const steps = await Promise.all(this.config.steps.map(async step => {
|
||||
const baseStep = {
|
||||
id: step.id,
|
||||
type: step.type,
|
||||
title: step.title,
|
||||
content: step.content,
|
||||
// For question steps, don't send correct answers
|
||||
...(step.type === 'question' && {
|
||||
content: step.content
|
||||
};
|
||||
|
||||
// For question steps, don't send correct answers
|
||||
if (step.type === 'question') {
|
||||
return {
|
||||
...baseStep,
|
||||
questionType: step.questionType,
|
||||
question: step.question,
|
||||
maxPoints: step.maxPoints,
|
||||
@@ -205,13 +205,30 @@ class LessonModule {
|
||||
text: opt.text
|
||||
// isCorrect and points are intentionally omitted
|
||||
}))
|
||||
}),
|
||||
// For interactive steps, send component info
|
||||
...(step.type === 'interactive' && {
|
||||
};
|
||||
}
|
||||
|
||||
// For interactive steps, fetch and include interactive data
|
||||
if (step.type === 'interactive') {
|
||||
const interactiveData = await this.getInteractiveData(step.id);
|
||||
return {
|
||||
...baseStep,
|
||||
interactiveComponent: step.interactiveComponent,
|
||||
componentProps: step.componentProps
|
||||
})
|
||||
})),
|
||||
componentProps: step.componentProps,
|
||||
interactiveData
|
||||
};
|
||||
}
|
||||
|
||||
return baseStep;
|
||||
}));
|
||||
|
||||
return {
|
||||
lessonKey: this.lessonKey,
|
||||
title: this.config.title,
|
||||
description: this.config.description,
|
||||
difficultyLevel: this.config.difficultyLevel,
|
||||
estimatedDuration: this.config.estimatedDuration,
|
||||
steps,
|
||||
scoring: {
|
||||
maxTotalPoints: this.config.scoring?.maxTotalPoints || 100,
|
||||
passingScore: this.config.scoring?.passingScore || 70
|
||||
@@ -219,6 +236,44 @@ class LessonModule {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Award points for interactive component discoveries
|
||||
* This method can be called by lesson modules to award points dynamically
|
||||
* @param {number} participantId - Participant ID
|
||||
* @param {number} eventLessonId - Event lesson ID
|
||||
* @param {number} points - Points to award
|
||||
* @param {string} reason - Reason for points (for tracking)
|
||||
* @returns {Promise<number>} New total score
|
||||
*/
|
||||
async awardPoints(participantId, eventLessonId, points, reason) {
|
||||
const progressQueries = require('../../src/models/queries/progress.queries');
|
||||
|
||||
// Get or create progress
|
||||
let progress = await progressQueries.getLessonProgress(participantId, eventLessonId);
|
||||
|
||||
if (!progress) {
|
||||
// Auto-start lesson if not started
|
||||
progress = await progressQueries.startLesson(participantId, eventLessonId);
|
||||
}
|
||||
|
||||
// Award points
|
||||
const newScore = await progressQueries.updateScore(progress.id, points);
|
||||
|
||||
// Optionally save the discovery reason for tracking
|
||||
if (reason) {
|
||||
await progressQueries.saveAnswer(
|
||||
progress.id,
|
||||
`interactive-${Date.now()}`,
|
||||
{ type: 'interactive', reason },
|
||||
true,
|
||||
points,
|
||||
reason
|
||||
);
|
||||
}
|
||||
|
||||
return newScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full configuration (for debugging/admin)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user