From 04aa52effe5942d1fc245961977dade1a482087b Mon Sep 17 00:00:00 2001 From: Eddy Chen <89349085+ecxyzzy@users.noreply.github.com> Date: Thu, 28 Dec 2023 01:33:51 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20type=20errors=20with=20ne?= =?UTF-8?q?w=20schema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/lib/utils.ts | 20 ++++++++++++++----- apps/api/src/routes/v1/rest/courses/lib.ts | 6 +++--- .../api/src/routes/v1/rest/instructors/lib.ts | 4 ++-- .../src/instructor-scraper/index.ts | 8 ++++---- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/api/src/lib/utils.ts b/apps/api/src/lib/utils.ts index 1ed1a295..4d28e479 100644 --- a/apps/api/src/lib/utils.ts +++ b/apps/api/src/lib/utils.ts @@ -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"]; @@ -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, }; } diff --git a/apps/api/src/routes/v1/rest/courses/lib.ts b/apps/api/src/routes/v1/rest/courses/lib.ts index aa13a485..1292fc78 100644 --- a/apps/api/src/routes/v1/rest/courses/lib.ts +++ b/apps/api/src/routes/v1/rest/courses/lib.ts @@ -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 }; diff --git a/apps/api/src/routes/v1/rest/instructors/lib.ts b/apps/api/src/routes/v1/rest/instructors/lib.ts index e76d553f..88070d4a 100644 --- a/apps/api/src/routes/v1/rest/instructors/lib.ts +++ b/apps/api/src/routes/v1/rest/instructors/lib.ts @@ -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() }, })), }); diff --git a/tools/registrar-scraper/src/instructor-scraper/index.ts b/tools/registrar-scraper/src/instructor-scraper/index.ts index b1dda259..42c407a6 100644 --- a/tools/registrar-scraper/src/instructor-scraper/index.ts +++ b/tools/registrar-scraper/src/instructor-scraper/index.ts @@ -26,7 +26,7 @@ type InstructorsData = { }; type InstructorsInfo = { - [ucinetid: string]: Instructor; + [ucinetid: string]: Omit; }; type InstructorsLog = { @@ -139,7 +139,7 @@ export async function getInstructors( } }); }); - const instructorPromises: Promise<[string, Instructor]>[] = []; + const instructorPromises: Promise<[string, Omit]>[] = []; Object.keys(instructorsDict).forEach((name) => { const schools = instructorsDict[name].schools; const related_departments = Array.from(instructorsDict[name].courses); @@ -214,9 +214,9 @@ async function getInstructor( relatedDepartments: string[], attempts: number, year_threshold: number, -): Promise<[string, Instructor]> { +): Promise<[string, Omit]> { logger.info(`Scraping data for ${instructorName}`); - const instructorObject: Instructor = { + const instructorObject: Omit = { name: instructorName, ucinetid: "", title: "",