feat(bisaya-course): update lesson retrieval and didactics processing
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s

- Refactored the lesson retrieval logic to include lesson number and title in the query, improving data handling.
- Updated the didactics processing to utilize a lesson-like object instead of fetching lessons by primary key, enhancing performance.
- Improved error handling and ensured proper closure of the database connection after execution.
This commit is contained in:
Torsten Schulz (local)
2026-04-16 22:36:15 +02:00
parent c1421db72c
commit 229bdc96bf

View File

@@ -463,11 +463,12 @@ async function updateBisayaDidactics() {
return; return;
} }
const lessons = await sequelize.query( const lessonRows = await sequelize.query(
`SELECT l.id `SELECT l.id, l.lesson_number, l.title
FROM community.vocab_course_lesson l FROM community.vocab_course_lesson l
JOIN community.vocab_course c ON c.id = l.course_id JOIN community.vocab_course c ON c.id = l.course_id
WHERE c.language_id = :languageId`, WHERE c.language_id = :languageId
ORDER BY c.id, l.lesson_number`,
{ {
replacements: { languageId: bisayaLanguage.id }, replacements: { languageId: bisayaLanguage.id },
type: sequelize.QueryTypes.SELECT type: sequelize.QueryTypes.SELECT
@@ -475,10 +476,13 @@ async function updateBisayaDidactics() {
); );
let updated = 0; let updated = 0;
for (const row of lessons) { for (const row of lessonRows) {
const lesson = await VocabCourseLesson.findByPk(row.id); const lessonLike = {
const didactics = resolveDidacticsForLesson(lesson); title: row.title,
const pedagogy = getBisayaLessonPedagogy(lesson.lessonNumber); lessonNumber: row.lesson_number
};
const didactics = resolveDidacticsForLesson(lessonLike);
const pedagogy = getBisayaLessonPedagogy(lessonLike.lessonNumber);
if (!didactics && !pedagogy) continue; if (!didactics && !pedagogy) continue;
const patch = {}; const patch = {};
@@ -499,21 +503,24 @@ async function updateBisayaDidactics() {
patch.isIntensiveReview = Boolean(pedagogy.isIntensiveReview); patch.isIntensiveReview = Boolean(pedagogy.isIntensiveReview);
} }
await lesson.update(patch); await VocabCourseLesson.update(patch, { where: { id: row.id } });
updated++; updated++;
console.log(`✅ Didaktik aktualisiert: Lektion ${lesson.lessonNumber} - ${lesson.title}`); console.log(`✅ Didaktik aktualisiert: Lektion ${lessonLike.lessonNumber} - ${lessonLike.title}`);
} }
console.log(`\n🎉 Fertig. ${updated} Lektion(en) aktualisiert.`); console.log(`\n🎉 Fertig. ${updated} Lektion(en) aktualisiert.`);
} }
updateBisayaDidactics() async function main() {
.then(() => { try {
sequelize.close(); await updateBisayaDidactics();
process.exit(0); } catch (error) {
})
.catch((error) => {
console.error('❌ Fehler:', error); console.error('❌ Fehler:', error);
sequelize.close(); process.exitCode = 1;
process.exit(1); } finally {
}); await sequelize.close();
}
process.exit(process.exitCode ?? 0);
}
main();