Refactor bisaya course progress reset logic: Replace raw SQL queries with Sequelize ORM methods for fetching lesson and exercise IDs. This improves code readability and maintainability while ensuring consistent database interactions.
This commit is contained in:
@@ -98,21 +98,26 @@ const LESSON_DIDACTICS = {
|
||||
async function resetBisayaProgress(courseIds) {
|
||||
if (courseIds.length === 0) return { lessonProgress: 0, exerciseProgress: 0 };
|
||||
|
||||
const lessonIds = await sequelize.query(
|
||||
`SELECT id FROM community.vocab_course_lesson WHERE course_id = ANY(:courseIds)`,
|
||||
{
|
||||
replacements: { courseIds },
|
||||
type: sequelize.QueryTypes.SELECT
|
||||
}
|
||||
);
|
||||
const lessonIds = await VocabCourseLesson.findAll({
|
||||
where: {
|
||||
courseId: {
|
||||
[Op.in]: courseIds
|
||||
}
|
||||
},
|
||||
attributes: ['id']
|
||||
});
|
||||
|
||||
const exerciseIds = await sequelize.query(
|
||||
`SELECT id FROM community.vocab_grammar_exercise WHERE lesson_id = ANY(:lessonIds)`,
|
||||
{
|
||||
replacements: { lessonIds: lessonIds.map((row) => row.id) || [0] },
|
||||
type: sequelize.QueryTypes.SELECT
|
||||
}
|
||||
);
|
||||
const numericLessonIds = lessonIds.map((row) => row.id);
|
||||
const exerciseIds = numericLessonIds.length > 0
|
||||
? await VocabGrammarExercise.findAll({
|
||||
where: {
|
||||
lessonId: {
|
||||
[Op.in]: numericLessonIds
|
||||
}
|
||||
},
|
||||
attributes: ['id']
|
||||
})
|
||||
: [];
|
||||
|
||||
const deletedLessonProgress = await VocabCourseProgress.destroy({
|
||||
where: { courseId: { [Op.in]: courseIds } }
|
||||
|
||||
Reference in New Issue
Block a user