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