From 6a363aeb5ccb1c11e15db317b34c4f04a3c9aafc Mon Sep 17 00:00:00 2001 From: Samuel Gunter Date: Fri, 4 Oct 2024 21:39:30 -0500 Subject: [PATCH] fix: grade dist when no instructor (#269) --- src/views/lib/database/queryDistribution.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/views/lib/database/queryDistribution.ts b/src/views/lib/database/queryDistribution.ts index 55c40162c..10ff08e2f 100644 --- a/src/views/lib/database/queryDistribution.ts +++ b/src/views/lib/database/queryDistribution.ts @@ -1,5 +1,6 @@ import type { Course, Semester } from '@shared/types/Course'; import type { CourseSQLRow, Distribution } from '@shared/types/Distribution'; +import type { QueryExecResult } from 'sql.js'; import { initializeDB } from './initializeDB'; @@ -20,9 +21,15 @@ export async function queryAggregateDistribution(course: Course): Promise<[Distr const db = await initializeDB(); const [query, params] = generateQuery(course, null, true); - let res = db.exec(query, params)?.[0]; - let instructorIncluded = true; - if (!res?.columns?.length) { + let res: QueryExecResult | undefined; + let instructorIncluded = params[':instructor_last'] !== undefined; + if (instructorIncluded) { + // Only check for data on an instructor if the course has an instructor + res = db.exec(query, params)?.[0]; + } + + if (!instructorIncluded || !res?.columns?.length) { + // Either no instructor for the class, or no data for the instructor instructorIncluded = false; const [queryWithoutInstructor, paramsWithoutInstructor] = generateQuery(course, null, false); res = db.exec(queryWithoutInstructor, paramsWithoutInstructor)?.[0];