21 lines
860 B
TypeScript
21 lines
860 B
TypeScript
import { mockCourses } from "@/lib/data/mockCourses";
|
|
import { getTeacherCourseBySlug, getTeacherCourses } from "@/lib/data/teacherCourses";
|
|
import type { Course } from "@/types/course";
|
|
|
|
export const getAllCourses = (): Course[] => {
|
|
const teacherCourses = getTeacherCourses();
|
|
if (teacherCourses.length === 0) return mockCourses;
|
|
|
|
const teacherSlugs = new Set(teacherCourses.map((course) => course.slug));
|
|
const baseCourses = mockCourses.filter((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[] => getAllCourses().map((course) => course.slug);
|