- Added formatting for transformation exercises to display prompts as "Übersetze 'X' ins Bisaya", improving clarity for users. - Updated the buildChoiceOptions method to exclude the prompt from the choice options, ensuring a more relevant selection for multiple choice questions. - Enhanced console logging to provide better insights into the prompt and answer during choice option creation, aiding in debugging and user feedback.
89 lines
2.6 KiB
JavaScript
Executable File
89 lines
2.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Script zum Löschen ALLER "Familienwörter"-Übungen aus Bisaya-Kursen
|
|
*
|
|
* Verwendung:
|
|
* node backend/scripts/delete-all-family-words-exercises.js
|
|
*
|
|
* Löscht alle Grammatik-Übungen von "Familienwörter"-Lektionen, um Platz für neue zu schaffen.
|
|
*/
|
|
|
|
import { sequelize } from '../utils/sequelize.js';
|
|
import VocabCourseLesson from '../models/community/vocab_course_lesson.js';
|
|
import VocabGrammarExercise from '../models/community/vocab_grammar_exercise.js';
|
|
|
|
async function deleteAllFamilyWordsExercises() {
|
|
await sequelize.authenticate();
|
|
console.log('Datenbankverbindung erfolgreich hergestellt.\n');
|
|
|
|
// Finde alle Bisaya-Kurse
|
|
const [bisayaLanguage] = await sequelize.query(
|
|
`SELECT id FROM community.vocab_language WHERE name = 'Bisaya' LIMIT 1`,
|
|
{
|
|
type: sequelize.QueryTypes.SELECT
|
|
}
|
|
);
|
|
|
|
if (!bisayaLanguage) {
|
|
console.error('❌ Bisaya-Sprache nicht gefunden.');
|
|
return;
|
|
}
|
|
|
|
const courses = await sequelize.query(
|
|
`SELECT id, title FROM community.vocab_course WHERE language_id = :languageId`,
|
|
{
|
|
replacements: { languageId: bisayaLanguage.id },
|
|
type: sequelize.QueryTypes.SELECT
|
|
}
|
|
);
|
|
|
|
console.log(`Gefunden: ${courses.length} Bisaya-Kurse\n`);
|
|
|
|
let totalDeleted = 0;
|
|
let totalLessons = 0;
|
|
|
|
for (const course of courses) {
|
|
console.log(`📚 Kurs: ${course.title} (ID: ${course.id})`);
|
|
|
|
// Finde "Familienwörter"-Lektionen
|
|
const lessons = await VocabCourseLesson.findAll({
|
|
where: {
|
|
courseId: course.id,
|
|
title: 'Familienwörter'
|
|
},
|
|
order: [['lessonNumber', 'ASC']]
|
|
});
|
|
|
|
console.log(` ${lessons.length} "Familienwörter"-Lektionen gefunden`);
|
|
|
|
for (const lesson of lessons) {
|
|
// Lösche ALLE bestehenden Übungen
|
|
const deletedCount = await VocabGrammarExercise.destroy({
|
|
where: { lessonId: lesson.id }
|
|
});
|
|
|
|
console.log(` 🗑️ Lektion ${lesson.lessonNumber}: "${lesson.title}" - ${deletedCount} Übung(en) gelöscht`);
|
|
totalDeleted += deletedCount;
|
|
totalLessons++;
|
|
}
|
|
|
|
console.log('');
|
|
}
|
|
|
|
console.log(`\n🎉 Zusammenfassung:`);
|
|
console.log(` ${totalLessons} Lektionen bearbeitet`);
|
|
console.log(` ${totalDeleted} Übungen gelöscht`);
|
|
console.log(`\n💡 Hinweis: Führe jetzt das update-family-words-exercises.js Script aus, um neue Übungen zu erstellen.`);
|
|
}
|
|
|
|
deleteAllFamilyWordsExercises()
|
|
.then(() => {
|
|
sequelize.close();
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
console.error('❌ Fehler:', error);
|
|
sequelize.close();
|
|
process.exit(1);
|
|
});
|