Skip to content

Commit 89df0ea

Browse files
committed
fix: fetchPaginatedData
1 parent abcc907 commit 89df0ea

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

apps/datapuller/src/lib/api/sis-api.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { Logger } from "tslog";
22

3-
export async function fetchPaginatedData<T, R>(
3+
import { HttpResponse } from "@repo/sis-api/courses";
4+
5+
export async function fetchPaginatedData<
6+
T,
7+
R,
8+
API extends Record<string, (...args: any[]) => Promise<HttpResponse<any>>>,
9+
Method extends keyof API,
10+
>(
411
logger: Logger<unknown>,
5-
api: any,
12+
api: API,
613
termIds: string[] | null,
7-
method: string,
14+
method: Method,
815
headers: Record<string, string>,
9-
responseProcessor: (data: any) => R[],
16+
responseProcessor: (data: Awaited<ReturnType<API[Method]>>["data"]) => R[],
1017
itemFilter: (item: R) => boolean,
1118
itemProcessor: (item: R) => T
1219
): Promise<T[]> {

apps/datapuller/src/lib/classes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { fetchPaginatedData } from "./api/sis-api";
77

88
// Include relevant fields missing from the automatically generated type
99
type CombinedClass = Class & {
10-
requisites: {
10+
requisites?: {
1111
code: {
1212
type: string;
1313
};
@@ -91,7 +91,7 @@ export const getClasses = async (
9191
) => {
9292
const classesAPI = new ClassesAPI();
9393

94-
const courses = await fetchPaginatedData<IClassItem, CombinedClass>(
94+
const courses = await fetchPaginatedData(
9595
logger,
9696
classesAPI.v1,
9797
termIds || null,
@@ -100,7 +100,7 @@ export const getClasses = async (
100100
app_id: id,
101101
app_key: key,
102102
},
103-
(data) => data.apiResponse.response.classes || [],
103+
(data) => data.apiResponse?.response.classes || [],
104104
filterClass,
105105
formatClass
106106
);

apps/datapuller/src/lib/courses.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { Course, CoursesAPI } from "@repo/sis-api/courses";
66
import { fetchPaginatedData } from "./api/sis-api";
77

88
// Include relevant fields missing from the automically generated type
9-
type CombinedCourse = Course;
10-
// type CombinedCourse = Course & {
11-
// gradeReplacement: ClassCourse["gradeReplacement"];
12-
// };
9+
type CombinedCourse = Course & {
10+
gradeReplacement?: ICourseItem["gradeReplacement"];
11+
};
1312

1413
const filterCourse = (input: CombinedCourse): boolean => {
1514
return input.status?.code === "ACTIVE";
@@ -73,13 +72,11 @@ const formatCourse = (input: CombinedCourse) => {
7372
(c) => c.identifiers?.find((i) => i.type === "cs-course-id")?.id || ""
7473
),
7574
},
76-
// gradeReplacement: {
77-
// text: input.gradeReplacement?.gradeReplacementText,
78-
// group: input.gradeReplacement?.gradeReplacementGroup,
79-
// courses: input.gradeReplacement?.gradeReplacementCourses?.map(
80-
// (c) => c.identifiers?.find((i) => i.type === "cs-course-id")?.id || ""
81-
// ),
82-
// },
75+
gradeReplacement: {
76+
text: input.gradeReplacement?.text,
77+
group: input.gradeReplacement?.group,
78+
courses: input.gradeReplacement?.courses,
79+
},
8380
crossListing: input.crossListing?.courses,
8481
formatsOffered: {
8582
description: input.formatsOffered?.description,
@@ -144,7 +141,7 @@ export const getCourses = async (
144141
) => {
145142
const coursesAPI = new CoursesAPI();
146143

147-
const courses = await fetchPaginatedData<ICourseItem, CombinedCourse>(
144+
const courses = await fetchPaginatedData(
148145
logger,
149146
coursesAPI.v5,
150147
null,
@@ -153,11 +150,7 @@ export const getCourses = async (
153150
app_id: id,
154151
app_key: key,
155152
},
156-
(
157-
data: Awaited<
158-
ReturnType<typeof coursesAPI.v5.findCourseCollectionUsingGet>
159-
>["data"]
160-
) => data.apiResponse?.response.courses || [],
153+
(data) => data.apiResponse?.response.courses || [],
161154
filterCourse,
162155
formatCourse
163156
);

apps/datapuller/src/lib/enrollment.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ export const getEnrollmentSingulars = async (
8686
) => {
8787
const classesAPI = new ClassesAPI();
8888

89-
const sections = await fetchPaginatedData<
90-
IEnrollmentSingularItem,
91-
ClassSection
92-
>(
89+
const sections = await fetchPaginatedData(
9390
logger,
9491
classesAPI.v1,
9592
termIds || null,
@@ -98,7 +95,7 @@ export const getEnrollmentSingulars = async (
9895
app_id: id,
9996
app_key: key,
10097
},
101-
(data) => data.apiResponse.response.classSections || [],
98+
(data) => data.apiResponse?.response.classSections || [],
10299
filterSection,
103100
(input) => formatEnrollmentSingular(input, new Date())
104101
);

apps/datapuller/src/lib/sections.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const getSections = async (
119119
) => {
120120
const classesAPI = new ClassesAPI();
121121

122-
const sections = await fetchPaginatedData<ISectionItem, ClassSection>(
122+
const sections = await fetchPaginatedData(
123123
logger,
124124
classesAPI.v1,
125125
termIds || null,
@@ -128,7 +128,7 @@ export const getSections = async (
128128
app_id: id,
129129
app_key: key,
130130
},
131-
(data) => data.apiResponse.response.classSections || [],
131+
(data) => data.apiResponse?.response.classSections || [],
132132
filterSection,
133133
formatSection
134134
);

0 commit comments

Comments
 (0)