Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions apps/web/graphql/courses/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import { checkPermission } from "@courselit/utils";
import { error } from "../../services/logger";

const { open, itemsPerPage, blogPostSnippetLength, permissions } = constants;

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable blogPostSnippetLength.

export const getCourseOrThrow = async (
id: mongoose.Types.ObjectId | undefined,
Expand Down Expand Up @@ -93,31 +93,34 @@
]) || 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,
Expand Down
Loading