Skip to content

Commit

Permalink
fix: Term resolution for schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
mathhulk committed Oct 10, 2024
1 parent cd9b515 commit 53e0cf2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/backend/src/modules/schedule/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Semester } from "../../generated-types/graphql";
import { getTerm } from "../term/controller";
import { TermModule } from "../term/generated-types/module-types";
import {
createSchedule,
deleteSchedule,
getSchedule,
getSchedules,
updateSchedule,
} from "./controller";
import { IntermediateSchedule } from "./formatter";
import { ScheduleModule } from "./generated-types/module-types";

const resolvers: ScheduleModule.Resolvers = {
Expand All @@ -21,6 +25,17 @@ const resolvers: ScheduleModule.Resolvers = {
return schedule as unknown as ScheduleModule.Schedule;
},
},

Schedule: {
term: async (parent: IntermediateSchedule | ScheduleModule.Schedule) => {
if (parent.term) return parent.term;

const term = await getTerm(parent.year, parent.semester as Semester);

return term as unknown as TermModule.Term;
},
},

Mutation: {
deleteSchedule: async (_, { id }, context) => {
return await deleteSchedule(context, id);
Expand Down

0 comments on commit 53e0cf2

Please sign in to comment.