advance
This commit is contained in:
14
lib/data/courseCatalog.ts
Normal file → Executable file
14
lib/data/courseCatalog.ts
Normal file → Executable file
@@ -2,12 +2,14 @@ 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();
|
||||
if (teacherCourses.length === 0) return mockCourses;
|
||||
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) => !teacherSlugs.has(course.slug));
|
||||
const baseCourses = mockCourses.filter((course) => isPublished(course) && !teacherSlugs.has(course.slug));
|
||||
return [...baseCourses, ...teacherCourses];
|
||||
};
|
||||
|
||||
@@ -17,4 +19,8 @@ export const getCourseBySlug = (slug: string): Course | undefined => {
|
||||
return mockCourses.find((course) => course.slug === slug);
|
||||
};
|
||||
|
||||
export const getAllCourseSlugs = (): string[] => getAllCourses().map((course) => course.slug);
|
||||
export const getAllCourseSlugs = (): string[] => {
|
||||
const teacherCourses = getTeacherCourses();
|
||||
const all = [...mockCourses, ...teacherCourses];
|
||||
return all.map((course) => course.slug);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user