This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ rework enrollment history endpoint (#126)
- Loading branch information
Showing
8 changed files
with
184 additions
and
170 deletions.
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
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,21 @@ | ||
import type { WebsocEnrollmentHistory, WebsocEnrollmentHistoryEntry } from "@libs/db"; | ||
import type { EnrollmentHistory, Meeting } from "@peterportal-api/types"; | ||
|
||
const stringifyDate = (date: Date) => | ||
`${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; | ||
export const transformResults = ( | ||
results: Array<WebsocEnrollmentHistory & { entries: WebsocEnrollmentHistoryEntry[] }>, | ||
): EnrollmentHistory[] => | ||
results.map(({ entries, ...x }) => ({ | ||
...x, | ||
sectionCode: x.sectionCode.toString().padStart(5, "0"), | ||
meetings: x.meetings as Meeting[], | ||
dates: entries.map((y) => y.date).map(stringifyDate), | ||
maxCapacityHistory: entries.map((y) => y.maxCapacity), | ||
totalEnrolledHistory: entries.map((y) => y.totalEnrolled), | ||
waitlistHistory: entries.map((y) => y.waitlist), | ||
waitlistCapHistory: entries.map((y) => y.waitlistCap), | ||
requestedHistory: entries.map((y) => y.requested), | ||
newOnlyReservedHistory: entries.map((y) => y.newOnlyReserved), | ||
statusHistory: entries.map((y) => y.status), | ||
})); |
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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import { quarters, sectionTypes } from "@peterportal-api/types"; | ||
import { z } from "zod"; | ||
|
||
export const QuerySchema = z.object({ | ||
year: z | ||
.string() | ||
.regex(/^\d{4}$/, { message: "Invalid year provided" }) | ||
.optional(), | ||
quarter: z.enum(quarters, { invalid_type_error: "Invalid quarter provided" }).optional(), | ||
instructor: z.string().optional(), | ||
department: z.string().optional(), | ||
courseNumber: z.string().optional(), | ||
sectionCode: z | ||
.string() | ||
.regex(/^\d{5}$/, { message: "Invalid sectionCode provided" }) | ||
.transform((x) => Number.parseInt(x, 10)) | ||
.optional(), | ||
sectionType: z | ||
.enum(sectionTypes, { invalid_type_error: "Invalid sectionType provided" }) | ||
.optional(), | ||
}); | ||
export const QuerySchema = z | ||
.object({ | ||
year: z | ||
.string() | ||
.regex(/^\d{4}$/, { message: "Invalid year provided" }) | ||
.optional(), | ||
quarter: z.enum(quarters, { invalid_type_error: "Invalid quarter provided" }).optional(), | ||
instructor: z.string().optional(), | ||
department: z.string().optional(), | ||
courseNumber: z.string().optional(), | ||
sectionCode: z | ||
.string() | ||
.regex(/^\d{5}$/, { message: "Invalid sectionCode provided" }) | ||
.transform((x) => Number.parseInt(x, 10)) | ||
.optional(), | ||
sectionType: z | ||
.enum(sectionTypes, { invalid_type_error: "Invalid sectionType provided" }) | ||
.optional(), | ||
}) | ||
.refine( | ||
(x) => | ||
(x.department && x.courseNumber) || | ||
(x.sectionCode && x.year && x.quarter) || | ||
(x.instructor && x.courseNumber && x.year && x.quarter), | ||
{ | ||
message: | ||
"Must provide department and course number; section code and year/quarter; or instructor, course number, and year/quarter", | ||
}, | ||
); | ||
|
||
export type Query = z.infer<typeof QuerySchema>; |
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
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
Oops, something went wrong.