Skip to content
Merged
Show file tree
Hide file tree
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
24 changes: 19 additions & 5 deletions codewit/api/src/controllers/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ async function getStudentCoursesByUid(userUid: number): Promise<CourseResponse[]
return formatCourseResponse(courses, true);
}

export async function getStudentCourse(course_id: string, transaction?: Transaction): Promise<StudentCourse | null> {
export async function getStudentCourse(
course_id: string,
userUid: number,
transaction?: Transaction
): Promise<StudentCourse | null> {
const course = await Course.findOne({
where: { id: course_id },
include: [
Expand All @@ -295,9 +299,19 @@ export async function getStudentCourse(course_id: string, transaction?: Transact
Resource,
{
association: "demos",
include: [ UserDemoCompletion ],
include: [
{
model: UserDemoCompletion,
where: { userUid },
required: false,
},
],
},
{
model: UserModuleCompletion,
where: { userUid },
required: false,
},
UserModuleCompletion,
],
through: { attributes: ['ordering'] },
},
Expand All @@ -323,7 +337,7 @@ export async function getStudentCourse(course_id: string, transaction?: Transact

let completion = 0.0;

if (module_demo["UserDemoCompletions"]?.length ?? 0 != 0) {
if ((module_demo["UserDemoCompletions"]?.length ?? 0) !== 0) {
completion = module_demo["UserDemoCompletions"][0].completion;
}

Expand All @@ -348,7 +362,7 @@ export async function getStudentCourse(course_id: string, transaction?: Transact

let completion = 0.0;

if (course_module["UserModuleCompletions"]?.length ?? 0 != 0) {
if ((course_module["UserModuleCompletions"]?.length ?? 0) !== 0) {
completion = course_module["UserModuleCompletions"][0].completion;
}

Expand Down
6 changes: 3 additions & 3 deletions codewit/api/src/routes/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ courseRouter.get('/:uid', asyncHandle(async (req, res) => {
let student_view = "student_view" in req.query && req.query["student_view"] === "1";

if (student_and_instructor && student_view) {
let course = await getStudentCourse(req.params.uid);
let course = await getStudentCourse(req.params.uid, req.user.uid);

if (course == null) {
throw new Error("the course was not found when it was found?");
Expand Down Expand Up @@ -285,7 +285,7 @@ courseRouter.get('/:uid', asyncHandle(async (req, res) => {
...result,
});
} else if (found.is_student) {
let course = await getStudentCourse(req.params.uid);
let course = await getStudentCourse(req.params.uid, req.user.uid);

if (course == null) {
throw new Error("the course was not found when it was found?");
Expand Down Expand Up @@ -528,7 +528,7 @@ courseRouter.post("/:uid/register", asyncHandle(async (req, res) => {
}
);

let course = await getStudentCourse(req.params.uid, transaction);
let course = await getStudentCourse(req.params.uid, req.user.uid, transaction);

if (course == null) {
throw new Error("the course was not found when it was found?");
Expand Down