Add grammar exercise creation in course generation
- Integrated functionality to create example grammar exercises for grammar lessons during course creation. - Added a new helper function to generate gap fill and multiple choice exercises based on lesson data. - Enhanced logging to confirm the number of grammar exercises created, improving feedback during course setup.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
import { sequelize } from '../utils/sequelize.js';
|
||||
import VocabCourse from '../models/community/vocab_course.js';
|
||||
import VocabCourseLesson from '../models/community/vocab_course_lesson.js';
|
||||
import VocabGrammarExercise from '../models/community/vocab_grammar_exercise.js';
|
||||
import User from '../models/community/user.js';
|
||||
import crypto from 'crypto';
|
||||
import bcrypt from 'bcryptjs';
|
||||
@@ -330,8 +331,9 @@ async function createCourseForLanguage(targetLanguageId, nativeLanguageId, langu
|
||||
console.log(` ✅ Kurs erstellt: "${course.title}" (ID: ${course.id}, Share-Code: ${shareCode})`);
|
||||
|
||||
// Erstelle Lektionen
|
||||
const createdLessons = [];
|
||||
for (const lessonData of LESSON_TEMPLATE) {
|
||||
await VocabCourseLesson.create({
|
||||
const lesson = await VocabCourseLesson.create({
|
||||
courseId: course.id,
|
||||
chapterId: null,
|
||||
lessonNumber: lessonData.num,
|
||||
@@ -345,12 +347,78 @@ async function createCourseForLanguage(targetLanguageId, nativeLanguageId, langu
|
||||
targetScorePercent: lessonData.targetScore,
|
||||
requiresReview: lessonData.review
|
||||
});
|
||||
createdLessons.push({ lesson, lessonData });
|
||||
}
|
||||
|
||||
console.log(` ✅ ${LESSON_TEMPLATE.length} Lektionen erstellt`);
|
||||
|
||||
// Erstelle Beispiel-Grammatik-Übungen für Grammar-Lektionen
|
||||
let grammarExerciseCount = 0;
|
||||
for (const { lesson, lessonData } of createdLessons) {
|
||||
if (lessonData.type === 'grammar') {
|
||||
// Erstelle 2-3 Beispiel-Übungen für jede Grammar-Lektion
|
||||
const exercises = createExampleGrammarExercises(lesson.id, lessonData, ownerUserId);
|
||||
for (const exercise of exercises) {
|
||||
await VocabGrammarExercise.create(exercise);
|
||||
grammarExerciseCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (grammarExerciseCount > 0) {
|
||||
console.log(` ✅ ${grammarExerciseCount} Grammatik-Übungen erstellt`);
|
||||
}
|
||||
|
||||
return course;
|
||||
}
|
||||
|
||||
// Erstelle Beispiel-Grammatik-Übungen für eine Grammar-Lektion
|
||||
function createExampleGrammarExercises(lessonId, lessonData, ownerUserId) {
|
||||
const exercises = [];
|
||||
|
||||
// Beispiel-Übung 1: Gap Fill (Lückentext)
|
||||
exercises.push({
|
||||
lessonId: lessonId,
|
||||
exerciseTypeId: 1, // gap_fill
|
||||
exerciseNumber: 1,
|
||||
title: `${lessonData.title} - Übung 1`,
|
||||
instruction: 'Fülle die Lücken mit den richtigen Wörtern.',
|
||||
questionData: JSON.stringify({
|
||||
type: 'gap_fill',
|
||||
text: 'Hallo! Wie geht es {gap}? Mir geht es {gap}, danke!',
|
||||
gaps: 2
|
||||
}),
|
||||
answerData: JSON.stringify({
|
||||
type: 'gap_fill',
|
||||
answers: ['dir', 'gut']
|
||||
}),
|
||||
explanation: 'Die richtigen Antworten sind "dir" und "gut".',
|
||||
createdByUserId: ownerUserId
|
||||
});
|
||||
|
||||
// Beispiel-Übung 2: Multiple Choice
|
||||
exercises.push({
|
||||
lessonId: lessonId,
|
||||
exerciseTypeId: 2, // multiple_choice
|
||||
exerciseNumber: 2,
|
||||
title: `${lessonData.title} - Übung 2`,
|
||||
instruction: 'Wähle die richtige Antwort aus.',
|
||||
questionData: JSON.stringify({
|
||||
type: 'multiple_choice',
|
||||
question: 'Wie sagt man "Guten Tag" auf ' + lessonData.title.split(' - ')[0] + '?',
|
||||
options: ['Option A', 'Option B', 'Option C', 'Option D']
|
||||
}),
|
||||
answerData: JSON.stringify({
|
||||
type: 'multiple_choice',
|
||||
correctAnswer: 0
|
||||
}),
|
||||
explanation: 'Die richtige Antwort ist Option A.',
|
||||
createdByUserId: ownerUserId
|
||||
});
|
||||
|
||||
return exercises;
|
||||
}
|
||||
|
||||
async function findOrCreateSystemUser() {
|
||||
// Versuche zuerst einen System-Benutzer zu finden (z.B. mit username "system" oder "admin")
|
||||
let systemUser = await User.findOne({
|
||||
|
||||
Reference in New Issue
Block a user