MCPcopy Create free account
hub / github.com/code100x/cms / getFullCourseContent

Function getFullCourseContent

src/db/course.ts:272–327  ·  view source on GitHub ↗
(
  courseId: number,
)

Source from the content-addressed store, hash-verified

270//TODO: add a cache here
271
272export const getFullCourseContent = async (
273 courseId: number,
274): Promise<FullCourseContent[]> => {
275 // const value = cache.get('getFullCourseContent', [
276 // courseId.toString(),
277 // ]);
278 // if (value) {
279 // return value;
280 // }
281 const session = await getServerSession(authOptions);
282 if (!session?.user) {
283 return [];
284 }
285 const contents = await getAllContent();
286 const courseContent = await getRootCourseContent(courseId);
287 const videoProgress = await getVideoProgressForUser(session?.user?.id);
288 const bookmarkData = await getBookmarkData();
289 const contentMap = new Map<string, FullCourseContent>(
290 contents.map((content: any) => [
291 content.id,
292 {
293 ...content,
294 children: [],
295 bookmark: bookmarkData.find((x) => x.contentId === content.id),
296 videoProgress:
297 content.type === 'video'
298 ? {
299 duration: videoProgress.find((x) => x.contentId === content.id)
300 ?.currentTimestamp,
301 markAsCompleted: videoProgress.find(
302 (x) => x.contentId === content.id,
303 )?.markAsCompleted,
304 videoFullDuration: content.VideoMetadata?.duration,
305 }
306 : null,
307 },
308 ]),
309 );
310
311 const rootContents: FullCourseContent[] = [];
312
313 contents
314 .sort((a, b) => (a.id < b.id ? -1 : 1))
315 .forEach((content: any) => {
316 if (content.parentId) {
317 contentMap
318 .get(content.parentId)
319 ?.children?.push(contentMap.get(content.id)!);
320 } else if (courseContent.find((x: any) => x.contentId === content.id)) {
321 rootContents.push(contentMap.get(content.id)!);
322 }
323 });
324
325 await cache.set('getFullCourseContent', [courseId.toString()], rootContents);
326 return rootContents;
327};
328
329export const getCourseContent = async (

Callers 5

CourseFunction · 0.90
LayoutFunction · 0.90
CourseFunction · 0.90
UpdateCourseContentFunction · 0.90
UpdateCourseContentFunction · 0.90

Calls 6

getBookmarkDataFunction · 0.90
getAllContentFunction · 0.85
getRootCourseContentFunction · 0.85
getVideoProgressForUserFunction · 0.85
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected