changes
This commit is contained in:
1 parent
a99af426db
commit
8886aa8640
91 files changed
+2823
-773
No files matched your search
+8
-15
@@ -1,30 +1,23 @@
|
||||
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";
|
||||
|
||||
export async function getCourses(): Promise<Course[]> {
|
||||
const res = await query<CourseRow>(
|
||||
"SELECT * FROM courses WHERE published = true ORDER BY title ASC",
|
||||
`${COURSE_WITH_TAXONOMY_SELECT}
|
||||
WHERE c.published = true
|
||||
ORDER BY c.title ASC`,
|
||||
);
|
||||
return res.rows.map(rowToCourse);
|
||||
}
|
||||
|
||||
/** Distinct tags on published courses, most-used first (for public nav/filters). */
|
||||
export async function listPublishedCourseTags(): Promise<string[]> {
|
||||
const res = await query<{ tag: string }>(
|
||||
`SELECT tag
|
||||
FROM courses, UNNEST(tags) AS tag
|
||||
WHERE published = true
|
||||
GROUP BY tag
|
||||
ORDER BY COUNT(*) DESC, tag ASC`,
|
||||
);
|
||||
return res.rows.map((r) => r.tag);
|
||||
}
|
||||
|
||||
export async function getCourseById(id: string): Promise<Course | null> {
|
||||
const res = await query<CourseRow>(
|
||||
"SELECT * FROM courses WHERE published = true AND (id = $1 OR slug = $1) LIMIT 1",
|
||||
`${COURSE_WITH_TAXONOMY_SELECT}
|
||||
WHERE c.published = true AND (c.id = $1 OR c.slug = $1)
|
||||
LIMIT 1`,
|
||||
[id],
|
||||
);
|
||||
return res.rows[0] ? rowToCourse(res.rows[0]) : null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user