Skip to content

Commit

Permalink
fix: Required courses
Browse files Browse the repository at this point in the history
  • Loading branch information
mathhulk committed Oct 10, 2024
1 parent 53e0cf2 commit fbc40d1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
34 changes: 29 additions & 5 deletions apps/backend/src/modules/course/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,42 @@ export const getClassesByCourse = async (
};

export const getAssociatedCourses = async (courses: string[]) => {
const queries = courses.map((course) => ({
"subjectArea.code": course.split(" ")[0],
"catalogNumber.formatted": course.split(" ")[1],
}));
console.log(courses);

const queries = courses.map((course) => {
const split = course.split(" ");

const subject = split.slice(0, -1).join(" ");
const number = split[split.length - 1];

return {
"subjectArea.code": subject,
"catalogNumber.formatted": number,
};
});

const associatedCourses = await CourseModel.find({
$or: queries,
})
.sort({ fromDate: -1 })
.lean();

return associatedCourses.map(formatCourse);
console.log(associatedCourses);

return (
associatedCourses
// TODO: Properly filter out duplicates in the query
.filter(
(course, index) =>
associatedCourses.findIndex(
(associatedCourse) =>
associatedCourse.subjectArea?.code === course.subjectArea?.code &&
course.catalogNumber?.formatted ===
associatedCourse.catalogNumber?.formatted
) === index
)
.map(formatCourse)
);
};

export const getCourses = async (info: GraphQLResolveInfo) => {
Expand Down
12 changes: 8 additions & 4 deletions apps/backend/src/modules/course/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export function formatCourse(course: CourseType) {
classes: null,
crossListing: course.crossListing?.courses ?? [],
requiredCourses:
course.preparation?.requiredCourses.map?.(
(course) =>
`${course.subjectArea?.code} ${course.catalogNumber?.formatted}`
) ?? [],
course.preparation?.requiredCourses.map?.((course) => {
const split = course.displayName?.split(" ") as string[];

const subject = split.slice(0, -1).join(" ");
const number = split[split.length - 1];

return `${subject} ${number}`;
}) ?? [],

requirements: course.preparation?.requiredText,
description: course.description as string,
Expand Down
14 changes: 2 additions & 12 deletions apps/frontend/src/app/Discover/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormEvent, useState } from "react";

import { useApolloClient, useQuery } from "@apollo/client";
import { useApolloClient } from "@apollo/client";
import { ArrowRight, Calendar } from "iconoir-react";

import AverageGrade from "@/components/AverageGrade";
Expand All @@ -10,13 +10,7 @@ import CourseDrawer from "@/components/CourseDrawer";
import Footer from "@/components/Footer";
import NavigationBar from "@/components/NavigationBar";
import Units from "@/components/Units";
import {
GET_COURSE,
GET_COURSES,
GetCoursesResponse,
ICourse,
Semester,
} from "@/lib/api";
import { GET_COURSE, ICourse, Semester } from "@/lib/api";

import styles from "./Discover.module.scss";
import Placeholder from "./Placeholder";
Expand All @@ -33,10 +27,6 @@ export default function Discover() {
const [courses, setCourses] = useState<ICourse[]>([]);
const apolloClient = useApolloClient();

const { data } = useQuery<GetCoursesResponse>(GET_COURSES);

console.log(data);

const getCourse = async (name: string) => {
const [subject, courseNumber] = name.split(" ");

Expand Down

0 comments on commit fbc40d1

Please sign in to comment.