Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-11 12:12:29 +08:00
parent e1ffdab190
commit 82ea9c77c4
19 changed files with 530 additions and 122 deletions
+25 -16
View File
@@ -56,27 +56,41 @@ async function recomputeParentDurations(lessonId) {
const LESSON_LIST_COMPUTED = [
{
key: "unit_count",
label: "Used in units",
key: "course_count",
label: "Used in courses",
type: "number",
literal: `(
SELECT CAST(COUNT(*) AS INTEGER)
SELECT CAST(COUNT(DISTINCT c.course_id) AS INTEGER)
FROM unit_lessons ul
JOIN units u ON u.unit_id = ul.unit_id AND u."deletedAt" IS NULL
JOIN course_units cu ON cu.unit_id = u.unit_id
JOIN courses c ON c.course_id = cu.course_id AND c."deletedAt" IS NULL
WHERE ul.lesson_id = "Lesson"."lesson_id"
)`,
},
{
key: "course_bound",
key: "course_status",
label: "Course Status",
type: "boolean",
type: "text",
filterable: false,
literal: `(
SELECT EXISTS (
SELECT 1
FROM unit_lessons ul
JOIN course_units cu ON cu.unit_id = ul.unit_id
WHERE ul.lesson_id = "Lesson"."lesson_id"
)
CASE
WHEN NOT EXISTS (
SELECT 1 FROM unit_lessons ul
JOIN units u ON u.unit_id = ul.unit_id AND u."deletedAt" IS NULL
JOIN course_units cu ON cu.unit_id = u.unit_id
JOIN courses c ON c.course_id = cu.course_id AND c."deletedAt" IS NULL
WHERE ul.lesson_id = "Lesson"."lesson_id"
) THEN 'standalone'
WHEN EXISTS (
SELECT 1 FROM unit_lessons ul
JOIN units u ON u.unit_id = ul.unit_id AND u."deletedAt" IS NULL
JOIN course_units cu ON cu.unit_id = u.unit_id
JOIN courses c ON c.course_id = cu.course_id AND c."deletedAt" IS NULL
WHERE ul.lesson_id = "Lesson"."lesson_id" AND c.status = 'published'
) THEN 'published'
ELSE 'draft'
END
)`,
},
];
@@ -114,11 +128,6 @@ exports.getLessonsFlat = async (req, res) => {
WHERE ul.lesson_id = l.lesson_id) AS unit_count
FROM lessons l
WHERE l."deletedAt" IS NULL
AND NOT EXISTS (
SELECT 1 FROM unit_lessons ul2
JOIN course_units cu ON cu.unit_id = ul2.unit_id
WHERE ul2.lesson_id = l.lesson_id
)
ORDER BY l.title ASC
`, { type: sequelize.QueryTypes.SELECT });
return R.success(res, "Lessons retrieved.", rows);