mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user