From 3018b1f2e17b67a4fe3b7a0671cf6c9e1b3302f4 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 21 Jan 2026 13:22:03 +0100 Subject: [PATCH] Refactor updateFoodCareExercises function to optimize database queries and improve code clarity - Replaced the Sequelize findAll method with a raw SQL query to fetch Bisaya courses along with native language information, enhancing performance. - Updated variable names for consistency and clarity, ensuring better readability of the code. - Adjusted the handling of course owner IDs to align with the new query structure, improving data integrity. --- backend/scripts/update-food-care-exercises.js | 40 +++++++++------ .../src/i18n/locales/de/socialnetwork.json | 3 +- .../src/i18n/locales/en/socialnetwork.json | 3 +- frontend/src/views/social/VocabLessonView.vue | 49 +++++++++++++++++++ 4 files changed, 77 insertions(+), 18 deletions(-) diff --git a/backend/scripts/update-food-care-exercises.js b/backend/scripts/update-food-care-exercises.js index f960c1d..a97d7d1 100755 --- a/backend/scripts/update-food-care-exercises.js +++ b/backend/scripts/update-food-care-exercises.js @@ -512,16 +512,24 @@ async function updateFoodCareExercises() { return; } - const courses = await VocabCourse.findAll({ - where: { languageId: bisayaLanguage.id }, - include: [ - { - model: sequelize.models.VocabLanguage, - as: 'nativeLanguage', - attributes: ['name'] - } - ] - }); + const bisayaLanguageId = bisayaLanguage.id; + + // Hole alle Bisaya-Kurse mit native language info + const courses = await sequelize.query( + `SELECT + c.id, + c.title, + c.owner_user_id, + c.native_language_id, + nl.name as native_language_name + FROM community.vocab_course c + LEFT JOIN community.vocab_language nl ON c.native_language_id = nl.id + WHERE c.language_id = :bisayaLanguageId`, + { + replacements: { bisayaLanguageId }, + type: sequelize.QueryTypes.SELECT + } + ); console.log(`Gefunden: ${courses.length} Bisaya-Kurse\n`); @@ -530,7 +538,7 @@ async function updateFoodCareExercises() { for (const course of courses) { console.log(`📚 Kurs: ${course.title} (ID: ${course.id})`); - const nativeLangName = course.nativeLanguage?.name || 'Deutsch'; + const nativeLangName = course.native_language_name || 'Deutsch'; console.log(` Muttersprache: ${nativeLangName}`); // Finde "Essen & Fürsorge" und "Essen & Trinken" Lektionen @@ -587,7 +595,7 @@ async function updateFoodCareExercises() { correctAnswer: 0 }), explanation: conv.explanation, - createdByUserId: course.ownerUserId || systemUser.id + createdByUserId: course.owner_user_id || systemUser.id }); totalExercisesCreated++; @@ -613,7 +621,7 @@ async function updateFoodCareExercises() { correctAnswer: 0 }), explanation: conv.explanation, - createdByUserId: course.ownerUserId || systemUser.id + createdByUserId: course.owner_user_id || systemUser.id }); totalExercisesCreated++; } @@ -639,7 +647,7 @@ async function updateFoodCareExercises() { alternatives: [] }), explanation: conv.explanation, - createdByUserId: course.ownerUserId || systemUser.id + createdByUserId: course.owner_user_id || systemUser.id }); totalExercisesCreated++; } @@ -668,7 +676,7 @@ async function updateFoodCareExercises() { correctAnswer: 0 }), explanation: vocab.explanation, - createdByUserId: course.ownerUserId || systemUser.id + createdByUserId: course.owner_user_id || systemUser.id }); totalExercisesCreated++; @@ -694,7 +702,7 @@ async function updateFoodCareExercises() { correctAnswer: 0 }), explanation: vocab.explanation, - createdByUserId: course.ownerUserId || systemUser.id + createdByUserId: course.owner_user_id || systemUser.id }); totalExercisesCreated++; } diff --git a/frontend/src/i18n/locales/de/socialnetwork.json b/frontend/src/i18n/locales/de/socialnetwork.json index a8eba95..987244a 100644 --- a/frontend/src/i18n/locales/de/socialnetwork.json +++ b/frontend/src/i18n/locales/de/socialnetwork.json @@ -408,7 +408,8 @@ "recordingError": "Aufnahme-Fehler", "recognizedText": "Erkannter Text", "speechRecognitionNotSupported": "Speech Recognition wird von diesem Browser nicht unterstützt. Bitte verwende Chrome oder Edge.", - "keywords": "Schlüsselwörter" + "keywords": "Schlüsselwörter", + "switchBackToMultipleChoice": "Zurück zu Multiple Choice" } } } diff --git a/frontend/src/i18n/locales/en/socialnetwork.json b/frontend/src/i18n/locales/en/socialnetwork.json index 77fa422..7e3c913 100644 --- a/frontend/src/i18n/locales/en/socialnetwork.json +++ b/frontend/src/i18n/locales/en/socialnetwork.json @@ -408,7 +408,8 @@ "recordingError": "Recording error", "recognizedText": "Recognized Text", "speechRecognitionNotSupported": "Speech Recognition is not supported by this browser. Please use Chrome or Edge.", - "keywords": "Keywords" + "keywords": "Keywords", + "switchBackToMultipleChoice": "Switch back to Multiple Choice" } } } diff --git a/frontend/src/views/social/VocabLessonView.vue b/frontend/src/views/social/VocabLessonView.vue index 3522154..69a35de 100644 --- a/frontend/src/views/social/VocabLessonView.vue +++ b/frontend/src/views/social/VocabLessonView.vue @@ -110,6 +110,11 @@
+
+ +
= 80) { this.vocabTrainerMode = 'typing'; + this.vocabTrainerAutoSwitchedToTyping = true; // Markiere als automatisch gewechselt // Reset Stats für Texteingabe-Modus this.vocabTrainerCorrect = 0; this.vocabTrainerWrong = 0; @@ -1036,6 +1046,17 @@ export default { } } }, + switchBackToMultipleChoice() { + // Wechsle zurück zu Multiple Choice + this.vocabTrainerMode = 'multiple_choice'; + this.vocabTrainerAutoSwitchedToTyping = false; + // Reset Stats für Multiple Choice Modus + this.vocabTrainerCorrect = 0; + this.vocabTrainerWrong = 0; + this.vocabTrainerTotalAttempts = 0; + // Starte neue Frage im Multiple Choice Modus + this.nextVocabQuestion(); + }, buildChoiceOptions(correctAnswer, allVocabs, excludePrompt = null) { const options = new Set([correctAnswer]); // Normalisiere alle Werte für den Vergleich (trim + lowercase) @@ -1765,9 +1786,37 @@ export default { .vocab-answer-area.typing { display: flex; + flex-direction: column; gap: 10px; } +.mode-switch-notice { + margin-bottom: 10px; + padding: 10px; + background: #fff3cd; + border: 1px solid #ffc107; + border-radius: 4px; + text-align: center; +} + +.btn-switch-mode { + padding: 8px 16px; + background: #F9A22C; + color: #000000; + border: 1px solid #F9A22C; + border-radius: 4px; + cursor: pointer; + font-size: 0.9em; + font-weight: 500; + transition: background 0.05s; +} + +.btn-switch-mode:hover { + background: #fdf1db; + color: #7E471B; + border: 1px solid #7E471B; +} + .vocab-answer-area.multiple-choice { display: flex; flex-direction: column;