Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 type errors with new schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ecxyzzy committed Dec 28, 2023
1 parent a97f16e commit 04aa52e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
20 changes: 15 additions & 5 deletions apps/api/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Course as PrismaCourse } from "@libs/db";
import { Course, CourseLevel, GECategory, PrerequisiteTree } from "@peterportal-api/types";
import {
Course,
CourseLevel,
CoursePreview,
GECategory,
InstructorPreview,
PrerequisiteTree,
} from "@peterportal-api/types";

const days = ["Su", "M", "Tu", "W", "Th", "F", "Sa"];

Expand Down Expand Up @@ -64,11 +71,14 @@ export function normalizeCourse(course: PrismaCourse): Course {
return {
...course,
courseLevel,
instructorHistory: course.instructorHistory as unknown as string[],
instructorHistory: course.instructorHistory,
instructors: course.instructors as unknown as InstructorPreview[],
prerequisiteTree: course.prerequisiteTree as unknown as PrerequisiteTree,
prerequisiteList: course.prerequisiteList as unknown as string[],
prerequisiteFor: course.prerequisiteFor as unknown as string[],
prerequisiteList: course.prerequisiteList,
prerequisiteFor: course.prerequisiteFor,
prerequisites: course.prerequisites as unknown as CoursePreview[],
dependencies: course.prerequisites as unknown as CoursePreview[],
geList,
terms: course.terms as unknown as string[],
terms: course.terms,
};
}
6 changes: 3 additions & 3 deletions apps/api/src/routes/v1/rest/courses/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ export function constructPrismaQuery(parsedQuery: Query): Prisma.CourseWhereInpu
if (parsedQuery.taughtByInstructors)
AND.push({
OR: parsedQuery.taughtByInstructors.map((instructor) => ({
instructorHistory: { array_contains: [instructor.toLowerCase()] },
instructorHistory: { has: instructor.toLowerCase() },
})),
});

if (parsedQuery.geCategory && parsedQuery.geCategory !== "ANY")
AND.push({ geList: { array_contains: [parsedQuery.geCategory] } });
AND.push({ geList: { has: parsedQuery.geCategory } });

if (parsedQuery.taughtInTerms)
AND.push({
OR: parsedQuery.taughtInTerms.map((term) => ({ terms: { array_contains: [term] } })),
OR: parsedQuery.taughtInTerms.map((term) => ({ terms: { has: term } })),
});

return { AND: AND.length ? AND : undefined };
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/routes/v1/rest/instructors/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export function constructPrismaQuery(parsedQuery: Query): Prisma.InstructorWhere

if (parsedQuery.schoolsContains)
AND.push({
OR: parsedQuery.schoolsContains.map((school) => ({ schools: { array_contains: [school] } })),
OR: parsedQuery.schoolsContains.map((school) => ({ schools: { has: school } })),
});

if (parsedQuery.relatedDepartmentsContains)
AND.push({
OR: parsedQuery.relatedDepartmentsContains.map((dept) => ({
relatedDepartments: { array_contains: [dept.toUpperCase()] },
relatedDepartments: { has: dept.toUpperCase() },
})),
});

Expand Down
8 changes: 4 additions & 4 deletions tools/registrar-scraper/src/instructor-scraper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type InstructorsData = {
};

type InstructorsInfo = {
[ucinetid: string]: Instructor;
[ucinetid: string]: Omit<Instructor, "courses">;
};

type InstructorsLog = {
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function getInstructors(
}
});
});
const instructorPromises: Promise<[string, Instructor]>[] = [];
const instructorPromises: Promise<[string, Omit<Instructor, "courses">]>[] = [];
Object.keys(instructorsDict).forEach((name) => {
const schools = instructorsDict[name].schools;
const related_departments = Array.from(instructorsDict[name].courses);
Expand Down Expand Up @@ -214,9 +214,9 @@ async function getInstructor(
relatedDepartments: string[],
attempts: number,
year_threshold: number,
): Promise<[string, Instructor]> {
): Promise<[string, Omit<Instructor, "courses">]> {
logger.info(`Scraping data for ${instructorName}`);
const instructorObject: Instructor = {
const instructorObject: Omit<Instructor, "courses"> = {
name: instructorName,
ucinetid: "",
title: "",
Expand Down

0 comments on commit 04aa52e

Please sign in to comment.