From 229bdc96bf61afb31c10b8734a7d2e2d5e5c7ebb Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Thu, 16 Apr 2026 22:36:15 +0200 Subject: [PATCH] feat(bisaya-course): update lesson retrieval and didactics processing - 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. --- backend/scripts/update-bisaya-didactics.js | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/backend/scripts/update-bisaya-didactics.js b/backend/scripts/update-bisaya-didactics.js index 5fa9092..9fdd682 100644 --- a/backend/scripts/update-bisaya-didactics.js +++ b/backend/scripts/update-bisaya-didactics.js @@ -463,11 +463,12 @@ async function updateBisayaDidactics() { return; } - const lessons = await sequelize.query( - `SELECT l.id + const lessonRows = await sequelize.query( + `SELECT l.id, l.lesson_number, l.title FROM community.vocab_course_lesson l 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 }, type: sequelize.QueryTypes.SELECT @@ -475,10 +476,13 @@ async function updateBisayaDidactics() { ); let updated = 0; - for (const row of lessons) { - const lesson = await VocabCourseLesson.findByPk(row.id); - const didactics = resolveDidacticsForLesson(lesson); - const pedagogy = getBisayaLessonPedagogy(lesson.lessonNumber); + for (const row of lessonRows) { + const lessonLike = { + title: row.title, + lessonNumber: row.lesson_number + }; + const didactics = resolveDidacticsForLesson(lessonLike); + const pedagogy = getBisayaLessonPedagogy(lessonLike.lessonNumber); if (!didactics && !pedagogy) continue; const patch = {}; @@ -499,21 +503,24 @@ async function updateBisayaDidactics() { patch.isIntensiveReview = Boolean(pedagogy.isIntensiveReview); } - await lesson.update(patch); + await VocabCourseLesson.update(patch, { where: { id: row.id } }); 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.`); } -updateBisayaDidactics() - .then(() => { - sequelize.close(); - process.exit(0); - }) - .catch((error) => { +async function main() { + try { + await updateBisayaDidactics(); + } catch (error) { console.error('āŒ Fehler:', error); - sequelize.close(); - process.exit(1); - }); + process.exitCode = 1; + } finally { + await sequelize.close(); + } + process.exit(process.exitCode ?? 0); +} + +main();