Skip to content

Commit

Permalink
Backend works for editing minors per plan
Browse files Browse the repository at this point in the history
  • Loading branch information
Suraj-Ram committed Dec 14, 2024
1 parent 60e25a9 commit 581a66e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
11 changes: 11 additions & 0 deletions packages/api/src/plan/plan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class PlanService {
): Promise<UpdateResult> {
const {
major: newMajorName,
minor: newMinorName,
catalogYear: newCatalogYear,
concentration: newConcentrationName,
schedule: newSchedule,
Expand Down Expand Up @@ -156,6 +157,10 @@ export class PlanService {
!newConcentrationName &&
currentPlan.major;

/** Wipe Minor => Remove existing minor from the plan. */
const isWipeMinorUpdate =
!newMinorName && !newCatalogYear && currentPlan.minor;

const isScheduleUpdate = newSchedule && !isMajorInfoUpdate;

if (
Expand Down Expand Up @@ -241,6 +246,7 @@ export class PlanService {
let name = currentPlan.name;
let schedule = currentPlan.schedule;
let major = isWipeMajorUpdate ? undefined : currentPlan.major;
let minor = isWipeMinorUpdate ? undefined : currentPlan.minor;
let catalogYear = isWipeMajorUpdate ? undefined : currentPlan.catalogYear;
let concentration = isWipeMajorUpdate
? undefined
Expand All @@ -260,9 +266,14 @@ export class PlanService {
concentration = newConcentrationName;
}

if (newMinorName) {
minor = newMinorName;
}

const newPlan = {
name,
major,
minor,
catalogYear,
concentration,
schedule,
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/components/Plan/EditPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export const EditPlanModal: React.FC<EditPlanModalProps> = ({ plan }) => {
);
} else {
try {
console.log("Updating plan", plan.id, newPlan);
await API.plans.update(plan.id, newPlan);
} catch (error) {
handleApiClientError(error as Error, router);
Expand Down
2 changes: 0 additions & 2 deletions packages/frontend/hooks/useMinor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type MinorReturn = MinorResponse & {
* @param minorName The name of the major, ex: "Computer Science, BSCS".
*/
export function useMinor(catalogYear: number, minorName: string): MinorReturn {
console.log("useMinor called with: ", catalogYear, minorName);
// debugger;
const key = `api/minor/${catalogYear}/${minorName}`;

const { data, ...rest } = useSWR(
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/utils/plan/getAllCoursesInMajor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const getAllCoursesInMinor = (
const minorRequirements = minor.requirementSections.reduce(
(courses: IRequiredCourse[], section: Section) => {
const requiredCourses: IRequiredCourse[] = [];
console.log("section requirements for minor");
console.log(section.requirements);
// console.log("section requirements for minor");
// console.log(section.requirements);
// if (section.requirements) {
// getRequiredCourses(section.requirements, requiredCourses);
// }
Expand Down

0 comments on commit 581a66e

Please sign in to comment.