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;
}
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();