changes
This commit is contained in:
1 parent
a99af426db
commit
8886aa8640
91 files changed
+2823
-773
No files matched your search
@@ -0,0 +1,88 @@
|
||||
import { query } from "@/lib/db";
|
||||
import type { TaxonomyRef } from "@/lib/types";
|
||||
|
||||
export interface CourseCategoryRecord extends TaxonomyRef {
|
||||
sortOrder: number;
|
||||
showInFilter: boolean;
|
||||
published: boolean;
|
||||
}
|
||||
|
||||
export interface CourseTagRecord extends TaxonomyRef {
|
||||
sortOrder: number;
|
||||
showInNav: boolean;
|
||||
showInFilter: boolean;
|
||||
published: boolean;
|
||||
}
|
||||
|
||||
type CategoryRow = {
|
||||
id: string;
|
||||
slug: string;
|
||||
label: string;
|
||||
sort_order: number;
|
||||
show_in_filter: boolean;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
type TagRow = {
|
||||
id: string;
|
||||
slug: string;
|
||||
label: string;
|
||||
sort_order: number;
|
||||
show_in_nav: boolean;
|
||||
show_in_filter: boolean;
|
||||
published: boolean;
|
||||
};
|
||||
|
||||
function mapCategory(row: CategoryRow): CourseCategoryRecord {
|
||||
return {
|
||||
id: row.id,
|
||||
slug: row.slug,
|
||||
label: row.label,
|
||||
sortOrder: row.sort_order,
|
||||
showInFilter: row.show_in_filter,
|
||||
published: row.published,
|
||||
};
|
||||
}
|
||||
|
||||
function mapTag(row: TagRow): CourseTagRecord {
|
||||
return {
|
||||
id: row.id,
|
||||
slug: row.slug,
|
||||
label: row.label,
|
||||
sortOrder: row.sort_order,
|
||||
showInNav: row.show_in_nav,
|
||||
showInFilter: row.show_in_filter,
|
||||
published: row.published,
|
||||
};
|
||||
}
|
||||
|
||||
export async function listPublishedCourseCategories(opts?: {
|
||||
filterOnly?: boolean;
|
||||
}): Promise<CourseCategoryRecord[]> {
|
||||
const filterOnly = opts?.filterOnly ?? false;
|
||||
const res = await query<CategoryRow>(
|
||||
`SELECT * FROM course_categories
|
||||
WHERE published = true
|
||||
AND ($1::boolean = false OR show_in_filter = true)
|
||||
ORDER BY sort_order ASC, label ASC`,
|
||||
[filterOnly],
|
||||
);
|
||||
return res.rows.map(mapCategory);
|
||||
}
|
||||
|
||||
export async function listPublishedCourseTags(opts?: {
|
||||
navOnly?: boolean;
|
||||
filterOnly?: boolean;
|
||||
}): Promise<CourseTagRecord[]> {
|
||||
const navOnly = opts?.navOnly ?? false;
|
||||
const filterOnly = opts?.filterOnly ?? false;
|
||||
const res = await query<TagRow>(
|
||||
`SELECT * FROM course_tags
|
||||
WHERE published = true
|
||||
AND ($1::boolean = false OR show_in_nav = true)
|
||||
AND ($2::boolean = false OR show_in_filter = true)
|
||||
ORDER BY sort_order ASC, label ASC`,
|
||||
[navOnly, filterOnly],
|
||||
);
|
||||
return res.rows.map(mapTag);
|
||||
}
|
||||
Reference in new issue
Block a user