27 lines
1.1 KiB
TypeScript
Executable File
27 lines
1.1 KiB
TypeScript
Executable File
import { mockCourses } from "@/lib/data/mockCourses";
|
|
import { getTeacherCourseBySlug, getTeacherCourses } from "@/lib/data/teacherCourses";
|
|
import type { Course } from "@/types/course";
|
|
|
|
const isPublished = (course: Course) => course.status === "Published";
|
|
|
|
export const getAllCourses = (): Course[] => {
|
|
const teacherCourses = getTeacherCourses().filter(isPublished);
|
|
if (teacherCourses.length === 0) return mockCourses.filter(isPublished);
|
|
|
|
const teacherSlugs = new Set(teacherCourses.map((course) => course.slug));
|
|
const baseCourses = mockCourses.filter((course) => isPublished(course) && !teacherSlugs.has(course.slug));
|
|
return [...baseCourses, ...teacherCourses];
|
|
};
|
|
|
|
export const getCourseBySlug = (slug: string): Course | undefined => {
|
|
const teacher = getTeacherCourseBySlug(slug);
|
|
if (teacher) return teacher;
|
|
return mockCourses.find((course) => course.slug === slug);
|
|
};
|
|
|
|
export const getAllCourseSlugs = (): string[] => {
|
|
const teacherCourses = getTeacherCourses();
|
|
const all = [...mockCourses, ...teacherCourses];
|
|
return all.map((course) => course.slug);
|
|
};
|