Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 reduce courses without sections for restriction code filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-wang0 committed Apr 10, 2024
1 parent fd7dd19 commit b947e67
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/api/src/routes/v1/rest/websoc/+endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PrismaClient } from "@libs/db";
import { createHandler } from "@libs/lambda";
import type { WebsocAPIResponse } from "@libs/uc-irvine-lib/websoc";
import type { WebsocCourse } from "@libs/uc-irvine-lib/websoc";
import { notNull } from "@libs/utils";
import { combineAndNormalizeResponses, sortResponse } from "@libs/websoc-utils";
import type { z } from "zod";
Expand Down Expand Up @@ -125,20 +126,27 @@ export const GET = createHandler(async (event, context, res) => {
}, onWarm);

function filterResults(query: z.infer<typeof QuerySchema>, websocResults: WebsocAPIResponse) {
if (!query.excludeRestrictionCodes) {
return websocResults;
}

const excludeRestrictions = query.excludeRestrictionCodes ?? [];

if (excludeRestrictions.length) {
return websocResults.schools.map((school) => {
const filteredDepartments = school.departments.map((department) => {
const filteredCourses = department.courses.map((course) => {
const filteredCourses = department.courses.reduce((acc: WebsocCourse[], course) => {
const filteredSections = course.sections.filter(
(section) =>
!section.restrictions
.split(/ and | or /)
.some((code: string) => excludeRestrictions.includes(code)),
);
return { ...course, sections: filteredSections };
});
if (filteredSections.length > 0) {
acc.push({ ...course, sections: filteredSections });
}
return acc;
}, []);
return { ...department, courses: filteredCourses };
});
return { ...school, departments: filteredDepartments };
Expand Down

0 comments on commit b947e67

Please sign in to comment.