Skip to content

Commit

Permalink
feat: Init terms
Browse files Browse the repository at this point in the history
  • Loading branch information
mathhulk committed Oct 5, 2024
1 parent 7c35d12 commit e604dd8
Show file tree
Hide file tree
Showing 20 changed files with 890 additions and 310 deletions.
20 changes: 10 additions & 10 deletions apps/backend/src/modules/catalog/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ const resolvers: CatalogModule.Resolvers = {
},

// @ts-expect-error - Not sure how to type this
Session: {
R: "1",
S: "12W",
A: "6W1",
B: "10W",
C: "8W",
D: "6W2",
E: "3W1",
F: "3W2",
},
// Session: {
// R: "1",
// S: "12W",
// A: "6W1",
// B: "10W",
// C: "8W",
// D: "6W2",
// E: "3W1",
// F: "3W2",
// },

CourseFinalExam: {
D: "To be decided by the instructor when the class is offered",
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/modules/catalog/typedefs/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ export default gql`
"Seminar"
SEM
"Demonstration"
DEM
}
enum InstructionMethod {
Expand Down
11 changes: 11 additions & 0 deletions apps/backend/src/modules/term/controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { TermModel } from "@repo/common";

import { Semester } from "../../generated-types/graphql";
import { formatTerm } from "./formatter";

export const getTerms = async () => {
const terms = await TermModel.find().lean();

return terms.map(formatTerm);
};

export const getTerm = async (year: number, semester: Semester) => {
const term = await TermModel.findOne({
name: `${year} ${semester}`,
}).lean();

if (!term) return null;

return formatTerm(term);
};
33 changes: 27 additions & 6 deletions apps/backend/src/modules/term/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,31 @@ import { TermType } from "@repo/common";

import { TermModule } from "./generated-types/module-types";

export function formatTerm(term: TermType): TermModule.Term {
export const formatDate = (date?: Date | null) => date?.toISOString();

export const formatSession = (session: TermType["sessions"][0]) => {
const { name, beginDate, endDate, temporalPosition } = session;

return {
// id,
name,
startDate: beginDate?.toISOString(),
endDate: endDate?.toISOString(),
temporalPosition: temporalPosition as TermModule.TemporalPosition,
} as TermModule.Session;
};

export const formatTerm = (term: TermType) => {
const { name, temporalPosition, sessions, beginDate, endDate } = term;

const [year, semester] = name.split(" ");

return {
semester: term.category.code,
year: term.academicYear,
active: term.temporalPosition === "Current",
};
}
semester: semester as TermModule.Semester,
year: parseInt(year),
temporalPosition: temporalPosition as TermModule.TemporalPosition,
sessions: sessions.map(formatSession),
startDate: beginDate?.toISOString(),
endDate: endDate?.toISOString(),
} as TermModule.Term;
};
3 changes: 2 additions & 1 deletion apps/backend/src/modules/term/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getTerms } from "./controller";
import { getTerm, getTerms } from "./controller";
import { TermModule } from "./generated-types/module-types";

const resolvers: TermModule.Resolvers = {
Query: {
terms: () => getTerms(),
term: (_, { year, semester }) => getTerm(year, semester),
},
};

Expand Down
42 changes: 36 additions & 6 deletions apps/backend/src/modules/term/typedefs/term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,62 @@ import { gql } from "graphql-tag";
const typedef = gql`
enum Semester {
# Summer
S
Summer
# Fall
F
Fall
# Spring
P
Spring
# Winter
W
Winter
}
enum TemporalPosition {
# Past
Past
# Current
Current
# Future
Future
}
"""
Session
"""
type Session {
temporalPosition: TemporalPosition!
# id: Int!
name: String!
startDate: String
endDate: String
}
"""
Term
"""
type Term {
semester: Semester!
year: String!
active: Boolean!
year: Int!
temporalPosition: TemporalPosition!
startDate: String
endDate: String
sessions: [Session!]!
}
type Query {
"""
Query for terms.
"""
terms: [Term]
"""
Query for a term.
"""
term(year: Int!, semester: Semester!): Term
}
`;

Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/utils/term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ export function getTermStartMonth(term: TermInput) {
Winter: `${term.year}-11-30`,
};

// @ts-expect-error - We know that the key exists
return startDates[term.semester];
}
13 changes: 1 addition & 12 deletions apps/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [
"@repo/eslint-config/index.cjs",
"plugin:react-hooks/recommended",
"plugin:cypress/recommended",
],
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
},
extends: ["@repo/eslint-config/index.cjs"],
};
98 changes: 52 additions & 46 deletions apps/frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ directive @cacheControl(

directive @auth on OBJECT | FIELD_DEFINITION

"""
Indicates exactly one field must be supplied and this field must not be `null`.
"""
directive @oneOf on INPUT_OBJECT

"""
User account info.
"""
Expand Down Expand Up @@ -83,12 +88,22 @@ type Query {
"""
Takes in a user's email and returns all the schedules they created.
"""
schedulesByUser: [Schedule!]
schedulesByUser: [Schedule]

"""
Takes in a schedule's ObjectID and returns a specific schedule.
"""
scheduleByID(id: String!): Schedule

"""
Query for terms.
"""
terms: [Term]

"""
Query for a term.
"""
term(year: Int!, semester: Semester!): Term
}

type Mutation {
Expand Down Expand Up @@ -146,16 +161,16 @@ type Course {
fromDate: String!
gradeAverage: Float
gradingBasis: CourseGradingBasis!
finalExam: CourseFinalExam!
finalExam: CourseFinalExam
academicCareer: AcademicCareer!
number: String!
subject: String!
title: String!
primaryInstructionMethod: InstructionMethod!
toDate: String!
typicallyOffered: [String!]
raw: JSONObject!
primaryInstructionMethod: InstructionMethod!
lastUpdated: ISODate!
typicallyOffered: [Semester!]
}

enum AcademicCareer {
Expand Down Expand Up @@ -246,6 +261,11 @@ enum ClassFinalExam {
Alernate Method
"""
A

"""
Common Final
"""
C
}

enum ClassGradingBasis {
Expand Down Expand Up @@ -285,46 +305,14 @@ enum ClassGradingBasis {
IOP
}

enum Session {
"""
Regular Academic Session
"""
R

"""
12-Week Summer Session
"""
S

"""
Session A
"""
A

"""
Session B
"""
B

"""
Session C
"""
C

"""
Session D
"""
D

"""
Session E
"""
E

"""
Session F
"""
F
"""
Session
"""
type Session {
temporalPosition: TemporalPosition!
name: String!
startDate: String
endDate: String
}

"""
Expand Down Expand Up @@ -589,7 +577,7 @@ type Meeting {
endTime: String!
startDate: String!
endDate: String!
location: String!
location: String
instructors: [Instructor!]!
}

Expand Down Expand Up @@ -647,9 +635,9 @@ input TermInput {
}

enum Semester {
Summer
Fall
Spring
Summer
Winter
}

Expand Down Expand Up @@ -745,3 +733,21 @@ type CustomEvent {
description: String
days_of_week: String
}

enum TemporalPosition {
Past
Current
Future
}

"""
Term
"""
type Term {
semester: Semester!
year: Int!
temporalPosition: TemporalPosition!
startDate: String
endDate: String
sessions: [Session!]!
}
Loading

0 comments on commit e604dd8

Please sign in to comment.