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.
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,11 @@
|
||||
</div>
|
||||
<!-- Texteingabe Modus -->
|
||||
<div v-else class="vocab-answer-area typing">
|
||||
<div v-if="vocabTrainerAutoSwitchedToTyping" class="mode-switch-notice">
|
||||
<button @click="switchBackToMultipleChoice" class="btn-switch-mode">
|
||||
{{ $t('socialnetwork.vocab.courses.switchBackToMultipleChoice') }}
|
||||
</button>
|
||||
</div>
|
||||
<input
|
||||
v-model="vocabTrainerAnswer"
|
||||
@keydown.enter.prevent="checkVocabAnswer"
|
||||
@@ -430,6 +435,7 @@ export default {
|
||||
vocabTrainerActive: false,
|
||||
vocabTrainerPool: [],
|
||||
vocabTrainerMode: 'multiple_choice', // 'multiple_choice' oder 'typing'
|
||||
vocabTrainerAutoSwitchedToTyping: false, // Track ob automatisch zu Typing gewechselt wurde
|
||||
vocabTrainerCorrect: 0,
|
||||
vocabTrainerWrong: 0,
|
||||
vocabTrainerTotalAttempts: 0,
|
||||
@@ -997,6 +1003,7 @@ export default {
|
||||
this.vocabTrainerActive = true;
|
||||
this.vocabTrainerPool = [...this.importantVocab];
|
||||
this.vocabTrainerMode = 'multiple_choice';
|
||||
this.vocabTrainerAutoSwitchedToTyping = false;
|
||||
this.vocabTrainerCorrect = 0;
|
||||
this.vocabTrainerWrong = 0;
|
||||
this.vocabTrainerTotalAttempts = 0;
|
||||
@@ -1008,6 +1015,8 @@ export default {
|
||||
},
|
||||
stopVocabTrainer() {
|
||||
this.vocabTrainerActive = false;
|
||||
this.vocabTrainerMode = 'multiple_choice';
|
||||
this.vocabTrainerAutoSwitchedToTyping = false;
|
||||
this.currentVocabQuestion = null;
|
||||
this.vocabTrainerAnswer = '';
|
||||
this.vocabTrainerSelectedChoice = null;
|
||||
@@ -1029,6 +1038,7 @@ export default {
|
||||
const successRate = (this.vocabTrainerCorrect / this.vocabTrainerTotalAttempts) * 100;
|
||||
if (successRate >= 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;
|
||||
|
||||
Reference in New Issue
Block a user