From 9c5cf8cbd3e71d13eb5e457588bbe4b79679f2a2 Mon Sep 17 00:00:00 2001 From: ravirajput10 Date: Thu, 5 Dec 2024 13:17:24 +0000 Subject: [PATCH] Fixed lessonId --- apps/web/graphql/courses/logic.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/web/graphql/courses/logic.ts b/apps/web/graphql/courses/logic.ts index ddec35584..413a505ae 100644 --- a/apps/web/graphql/courses/logic.ts +++ b/apps/web/graphql/courses/logic.ts @@ -93,31 +93,34 @@ export const getCourse = async ( ]) || checkOwnershipWithoutModel(course, ctx); if (isOwner) { + await loadFirstLesson(course, ctx); return course; } } if (course.published) { - if ( - [constants.course, constants.download].includes( - course.type as - | typeof constants.course - | typeof constants.download, - ) - ) { - const { nextLesson } = await getPrevNextCursor( - course.courseId, - ctx.subdomain._id, - ); - (course as any).firstLesson = nextLesson; - } - // course.groups = accessibleGroups; + await loadFirstLesson(course, ctx); return course; } else { throw new Error(responses.item_not_found); } }; +const loadFirstLesson = async (course: Course, ctx: GQLContext) => { + if ( + [constants.course, constants.download].includes( + course.type as typeof constants.course | typeof constants.download, + ) + ) { + const { nextLesson } = await getPrevNextCursor( + course.courseId, + ctx.subdomain._id, + ); + (course as any).firstLesson = nextLesson; + } + // course.groups = accessibleGroups; +}; + export const createCourse = async ( courseData: { title: string; type: Filter }, ctx: GQLContext,