-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SectionModel, SectionType, TermModel } from "@repo/common"; | ||
import { ClassesAPI } from "@repo/sis-api/classes"; | ||
|
||
import { config } from "../../config"; | ||
import { Semester } from "../../generated-types/graphql"; | ||
import { formatSection } from "../class/formatter"; | ||
|
||
export const getEnrollment = async ( | ||
year: number, | ||
semester: Semester, | ||
subject: string, | ||
courseNumber: string, | ||
number: string | ||
) => { | ||
const term = await TermModel.findOne({ | ||
name: `${year} ${semester}`, | ||
}); | ||
|
||
if (!term) throw new Error("Term not found"); | ||
|
||
const section = await SectionModel.findOne({ | ||
"class.session.term.id": term.id, | ||
"class.course.subjectArea.code": subject, | ||
"class.course.catalogNumber.formatted": courseNumber, | ||
number: number, | ||
}); | ||
|
||
if (!section) throw new Error("Section not found"); | ||
|
||
const client = new ClassesAPI(); | ||
|
||
const response = await client.v1.getClassSectionByTermAndSectionIdUsingGet( | ||
section.id, | ||
{ "term-id": term.id }, | ||
{ | ||
headers: { | ||
app_key: config.sis.CLASS_APP_KEY, | ||
app_id: config.sis.CLASS_APP_ID, | ||
}, | ||
} | ||
); | ||
|
||
const raw = response.data.apiResponse?.response.classSections?.[0]; | ||
|
||
if (!raw) throw new Error("Something went error"); | ||
|
||
return formatSection(raw as unknown as SectionType); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import resolver from "./resolver"; | ||
import typeDef from "./typedefs/enrollment"; | ||
|
||
export default { | ||
resolver, | ||
typeDef, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getEnrollment } from "./controller"; | ||
import { EnrollmentModule } from "./generated-types/module-types"; | ||
|
||
const resolvers: EnrollmentModule.Resolvers = { | ||
Query: { | ||
enrollment: async ( | ||
_, | ||
{ year, semester, subject, courseNumber, number } | ||
) => { | ||
const enrollment = await getEnrollment( | ||
year, | ||
semester, | ||
subject, | ||
courseNumber, | ||
number | ||
); | ||
|
||
return enrollment as unknown as EnrollmentModule.Section; | ||
}, | ||
}, | ||
}; | ||
|
||
export default resolvers; |
13 changes: 13 additions & 0 deletions
13
apps/backend/src/modules/enrollment/typedefs/enrollment.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { gql } from "graphql-tag"; | ||
|
||
export default gql` | ||
type Query { | ||
enrollment( | ||
year: Int! | ||
semester: Semester! | ||
subject: String! | ||
courseNumber: String! | ||
number: String! | ||
): Section! | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.