Enhance Bisaya course content creation: Update SQL query to include owner user ID and improve exercise handling logic. Implement checks for existing exercises and placeholder replacements for review lessons, ensuring better management of lesson content and user feedback.

This commit is contained in:
Torsten Schulz (local)
2026-02-02 09:58:35 +01:00
parent 640cdcf671
commit ce34bae16a
3 changed files with 188 additions and 52 deletions

View File

@@ -738,7 +738,7 @@ async function createBisayaCourseContent() {
}
const courses = await sequelize.query(
`SELECT id, title FROM community.vocab_course WHERE language_id = :languageId`,
`SELECT id, title, owner_user_id AS "ownerUserId" FROM community.vocab_course WHERE language_id = :languageId`,
{
replacements: { languageId: bisayaLanguage.id },
type: sequelize.QueryTypes.SELECT
@@ -761,24 +761,33 @@ async function createBisayaCourseContent() {
console.log(` ${lessons.length} Lektionen gefunden\n`);
for (const lesson of lessons) {
// Prüfe, ob bereits Übungen existieren
const exercises = getExercisesForLesson(lesson.title);
if (exercises.length === 0) {
const existingCount = await VocabGrammarExercise.count({ where: { lessonId: lesson.id } });
if (existingCount > 0) {
console.log(` ⏭️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - bereits ${existingCount} Übung(en) vorhanden`);
} else {
console.log(` ⚠️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - keine Übungen definiert`);
}
continue;
}
// Bei Woche-1-Wiederholung/Vokabeltest: Alte Platzhalter entfernen und ersetzen
const replacePlaceholders = ['Woche 1 - Wiederholung', 'Woche 1 - Vokabeltest'].includes(lesson.title);
const existingCount = await VocabGrammarExercise.count({
where: { lessonId: lesson.id }
});
if (existingCount > 0) {
if (existingCount > 0 && !replacePlaceholders) {
console.log(` ⏭️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - bereits ${existingCount} Übung(en) vorhanden`);
continue;
}
// Hole Übungen für diese Lektion
const exercises = getExercisesForLesson(lesson.title);
if (exercises.length === 0) {
console.log(` ⚠️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - keine Übungen definiert`);
continue;
if (replacePlaceholders && existingCount > 0) {
const deleted = await VocabGrammarExercise.destroy({ where: { lessonId: lesson.id } });
console.log(` 🗑️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - ${deleted} Platzhalter entfernt`);
}
// Erstelle Übungen
let exerciseNumber = 1;
for (const exerciseData of exercises) {