Files
Aut.ManagementFaculty/src/lib/data/course-taxonomy-sql.ts
T
smhk1376andCursor de800d27b1 Apply the public site UI checklist.
Align header, footer, brand, homepage course preview, faculty links, and the course catalog with the documented changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-16 14:05:33 +03:30

47 lines
1.3 KiB
TypeScript

/** Shared SELECT fragment: course row + JSON arrays of categories/tags/instructors. */
export const COURSE_WITH_TAXONOMY_SELECT = `
SELECT c.*,
COALESCE(
(
SELECT json_agg(
json_build_object('id', cat.id, 'slug', cat.slug, 'label', cat.label)
ORDER BY cat.sort_order ASC, cat.label ASC
)
FROM course_category_links l
JOIN course_categories cat ON cat.id = l.category_id
WHERE l.course_id = c.id
),
'[]'::json
) AS categories,
COALESCE(
(
SELECT json_agg(
json_build_object('id', t.id, 'slug', t.slug, 'label', t.label)
ORDER BY t.sort_order ASC, t.label ASC
)
FROM course_tag_links l
JOIN course_tags t ON t.id = l.tag_id
WHERE l.course_id = c.id
),
'[]'::json
) AS tags,
COALESCE(
(
SELECT json_agg(
json_build_object(
'id', f.id,
'name', f.name,
'title', f.title,
'profileUrl', f.profile_url
)
ORDER BY f.name ASC
)
FROM course_faculty_links l
JOIN faculty_members f ON f.id = l.faculty_id
WHERE l.course_id = c.id
),
'[]'::json
) AS instructors
FROM courses c
`;