From 0dcd9c52121d37eca5bedf4870f8b03fa029d2a7 Mon Sep 17 00:00:00 2001 From: ShireenKumar Date: Sun, 17 Nov 2024 22:21:06 -0500 Subject: [PATCH 1/2] fixed formatting of cs and game-dev JSON and added more conditions when calling getRequiredCourses --- .../parsed.initial.json | 86 +++++++++---------- .../utils/plan/getAllCoursesInMajor.ts | 6 +- 2 files changed, 45 insertions(+), 47 deletions(-) diff --git a/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json b/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json index cac54eea3..c602e86dd 100644 --- a/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json +++ b/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json @@ -285,50 +285,48 @@ "type": "XOM", "numCreditsMin": 12, "courses": [ - [ - { - "type": "RANGE", - "subject": "ARTD", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTE", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTF", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTG", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTH", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "GAME", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - } - ], + { + "type": "RANGE", + "subject": "ARTD", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTE", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTF", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTG", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTH", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "GAME", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, { "type": "RANGE", "subject": "CS", diff --git a/packages/frontend/utils/plan/getAllCoursesInMajor.ts b/packages/frontend/utils/plan/getAllCoursesInMajor.ts index 85154f0d7..68f7992e5 100644 --- a/packages/frontend/utils/plan/getAllCoursesInMajor.ts +++ b/packages/frontend/utils/plan/getAllCoursesInMajor.ts @@ -22,7 +22,7 @@ export const getAllCoursesInMajor = ( const majorRequirements = major.requirementSections.reduce( (courses: IRequiredCourse[], section: Section) => { const requiredCourses: IRequiredCourse[] = []; - getRequiredCourses(section.requirements, requiredCourses); + getRequiredCourses(section.requirements ?? [], requiredCourses); return courses.concat(requiredCourses); }, [] @@ -54,9 +54,9 @@ const getRequiredCourses = ( } else if (requirement.type === "COURSE") { requiredCourses.push(requirement); } else if (requirement.type === "SECTION") { - getRequiredCourses(requirement.requirements, requiredCourses); + getRequiredCourses(requirement.requirements ?? [], requiredCourses); } else { - getRequiredCourses(requirement.courses, requiredCourses); + getRequiredCourses(requirement.courses ?? [], requiredCourses); } } }; From 38fe9eea341cae03623c03e7d2bf1a8bfdc75b49 Mon Sep 17 00:00:00 2001 From: ShireenKumar Date: Thu, 21 Nov 2024 18:21:34 -0500 Subject: [PATCH 2/2] Created helper function to deal with nested arrays --- .../parsed.initial.json | 86 ++++++++++--------- .../utils/plan/getAllCoursesInMajor.ts | 10 +++ 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json b/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json index c602e86dd..cac54eea3 100644 --- a/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json +++ b/packages/api/src/major/majors/2023/computer-information-science/Computer_Science_and_Game_Development_BS/parsed.initial.json @@ -285,48 +285,50 @@ "type": "XOM", "numCreditsMin": 12, "courses": [ - { - "type": "RANGE", - "subject": "ARTD", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTE", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTF", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTG", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "ARTH", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, - { - "type": "RANGE", - "subject": "GAME", - "idRangeStart": 0, - "idRangeEnd": 9999, - "exceptions": [] - }, + [ + { + "type": "RANGE", + "subject": "ARTD", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTE", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTF", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTG", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "ARTH", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + }, + { + "type": "RANGE", + "subject": "GAME", + "idRangeStart": 0, + "idRangeEnd": 9999, + "exceptions": [] + } + ], { "type": "RANGE", "subject": "CS", diff --git a/packages/frontend/utils/plan/getAllCoursesInMajor.ts b/packages/frontend/utils/plan/getAllCoursesInMajor.ts index 68f7992e5..be376480b 100644 --- a/packages/frontend/utils/plan/getAllCoursesInMajor.ts +++ b/packages/frontend/utils/plan/getAllCoursesInMajor.ts @@ -55,8 +55,18 @@ const getRequiredCourses = ( requiredCourses.push(requirement); } else if (requirement.type === "SECTION") { getRequiredCourses(requirement.requirements ?? [], requiredCourses); + } else if (Array.isArray(requirement)) { + getRequiredCourses(extractRequirements(requirement), requiredCourses); } else { getRequiredCourses(requirement.courses ?? [], requiredCourses); } } }; + +const extractRequirements = (requirements: Requirement2[]): Requirement2[] => { + const extracted: Requirement2[] = []; + for (const value of requirements) { + extracted.push(value); + } + return extracted; +};