From 53e0cf26017e31183fadcf7dd84036e1957a3d39 Mon Sep 17 00:00:00 2001 From: Matthew Rowland Date: Wed, 9 Oct 2024 18:56:32 -0700 Subject: [PATCH] fix: Term resolution for schedules --- apps/backend/src/modules/schedule/resolver.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/backend/src/modules/schedule/resolver.ts b/apps/backend/src/modules/schedule/resolver.ts index 5c7f87b51..e03338363 100644 --- a/apps/backend/src/modules/schedule/resolver.ts +++ b/apps/backend/src/modules/schedule/resolver.ts @@ -1,3 +1,6 @@ +import { Semester } from "../../generated-types/graphql"; +import { getTerm } from "../term/controller"; +import { TermModule } from "../term/generated-types/module-types"; import { createSchedule, deleteSchedule, @@ -5,6 +8,7 @@ import { getSchedules, updateSchedule, } from "./controller"; +import { IntermediateSchedule } from "./formatter"; import { ScheduleModule } from "./generated-types/module-types"; const resolvers: ScheduleModule.Resolvers = { @@ -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);