Enhance course management by adding 'featured' and 'sort_order' fields to the database schema and related components. Update course filtering and display logic to prioritize featured courses in the catalog. Modify admin interfaces for course creation and editing to include new fields, ensuring proper handling in both the frontend and backend. Update documentation to reflect these changes.

This commit is contained in:
smhk1376 committed 2026-10-22 13:23:43 +03:30
1 parent 1641edfd01
commit 4b84409ed7
43 files changed
+703 -155

No files matched your search

+12 -7
View File
@@ -2,32 +2,37 @@ import { query } from "@/lib/db";
import type { Course } from "@/lib/types";
import { rowToCourse, type CourseRow } from "@/lib/db/mappers";
import { COURSE_WITH_TAXONOMY_SELECT } from "@/lib/data/course-taxonomy-sql";
import { ARCHIVE_TAG_ID } from "@/lib/course-catalog";
/** Past offerings tagged `tag-archive` — lowest catalog priority; excluded from home. */
const ARCHIVE_TAG_ID = "tag-archive";
/** Past offerings tagged `tag-archive` — catalog block of their own; excluded from home. */
const isArchiveCourseSql = `EXISTS (
SELECT 1 FROM course_tag_links ctl
WHERE ctl.course_id = c.id AND ctl.tag_id = '${ARCHIVE_TAG_ID}'
)`;
const catalogOrderSql = `CASE WHEN ${isArchiveCourseSql} THEN 1 ELSE 0 END ASC,
CASE WHEN c.featured THEN 0 ELSE 1 END ASC,
c.sort_order ASC,
c.title ASC`;
export async function getCourses(): Promise<Course[]> {
const res = await query<CourseRow>(
`${COURSE_WITH_TAXONOMY_SELECT}
WHERE c.published = true
ORDER BY CASE WHEN ${isArchiveCourseSql} THEN 1 ELSE 0 END ASC,
c.title ASC`,
ORDER BY ${catalogOrderSql}`,
);
return res.rows.map(rowToCourse);
}
/** Latest published courses for home preview (newest first; archive excluded). */
/** Priority-ordered published courses for home preview (archive excluded). */
export async function getLatestCourses(limit = 6): Promise<Course[]> {
const res = await query<CourseRow>(
`${COURSE_WITH_TAXONOMY_SELECT}
WHERE c.published = true
AND NOT ${isArchiveCourseSql}
ORDER BY c.created_at DESC, c.title ASC
ORDER BY CASE WHEN c.featured THEN 0 ELSE 1 END ASC,
c.sort_order ASC,
c.title ASC
LIMIT $1`,
[limit],
);