add: ver()

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-08 11:31:40 +08:00
parent 0e4cd86119
commit bb7e8fde08
29 changed files with 2234 additions and 780 deletions
+20 -3
View File
@@ -25,6 +25,8 @@ const sequelize = require('../config/db.config');
const CourseReadingProgress = require('../models/courses/course_reading_progress.mdl');
const Lesson = require('../models/courses/lessons.mdl');
const Unit = require('../models/courses/units.mdl');
const CourseUnit = require('../models/courses/course_units.mdl');
const UnitLesson = require('../models/courses/unit_lessons.mdl');
const CourseAssessment = require('../models/courses/course_assessment.mdl');
const QuizAttempt = require('../models/courses/quiz_attempt.mdl');
@@ -71,10 +73,18 @@ async function upsertProgress({ userId, courseId, type, referenceId, status }, t
// ─── Derivation helpers ───────────────────────────────────────────────────────
// Unit is completed when every non-deleted lesson under it has a completed row for this user.
// Unit is completed when every non-deleted lesson attached to it (via unit_lessons)
// has a completed row for this user.
async function deriveUnitStatus(userId, courseId, unitId, t) {
const lessons = await Lesson.findAll({
const links = await UnitLesson.findAll({
where: { unit_id: unitId },
attributes: ['lesson_id'],
transaction: t,
});
if (!links.length) return 'in_progress';
const lessons = await Lesson.findAll({
where: { lesson_id: links.map(l => l.lesson_id) },
attributes: ['uuid'],
transaction: t,
});
@@ -98,8 +108,15 @@ async function deriveUnitStatus(userId, courseId, unitId, t) {
// Course is completed when every non-deleted unit under it has a completed row for this user
// AND the course's assessment (if one has been built) has been passed by this user.
async function deriveCourseStatus(userId, courseId, t) {
const units = await Unit.findAll({
const links = await CourseUnit.findAll({
where: { course_id: courseId },
attributes: ['unit_id'],
transaction: t,
});
if (!links.length) return 'in_progress';
const units = await Unit.findAll({
where: { unit_id: links.map(l => l.unit_id) },
attributes: ['uuid'],
transaction: t,
});