Skip to content

Commit

Permalink
Merge pull request #556 from UTDNebula/prereq
Browse files Browse the repository at this point in the history
Prereq
  • Loading branch information
jasonappah authored Apr 4, 2023
2 parents e0daacb + 131c808 commit 9796da9
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/server/trpc/router/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const validatorRouter = router({
const coReqHash = new Map<string, Array<[Array<string>, number]>>();
const preReqHash = new Map<string, Array<[Array<string>, number]>>();
const coOrPreReqHash = new Map<string, Array<[Array<string>, number]>>();
// Regex to parse course from description of improperly parsed course
const re = /\b[A-Z]{2,4} \d{4}\b/;

/* Recursive function to check for prereqs.
* TODO: Move to a client side function. Possibly a hook.
*/
Expand Down Expand Up @@ -105,8 +108,13 @@ export const validatorRouter = router({
}
const temp: [Array<string>, number] = [[], 0];
for (const option of requirements.options) {
if (option.type === 'course') {
const course = courseMapWithIdKey.get(option.class_reference);
if (option.type === 'course' || option.type === 'other') {
// 'other' might be an improperly parsed course
// if it's not, `course` will be set to undefined so nothing will happen
const course =
option.type === 'course'
? courseMapWithIdKey.get(option.class_reference)
: option.description.match(re)?.[0];
if (course) {
const data = courseHash.get(course as string);
if (data === undefined) {
Expand All @@ -124,8 +132,6 @@ export const validatorRouter = router({
} else {
count++;
}
} else if (option.type === 'other') {
// count++;
}
}

Expand All @@ -150,8 +156,13 @@ export const validatorRouter = router({
}
const temp: [Array<string>, number] = [[], 0];
for (const option of requirements.options) {
if (option.type === 'course') {
const course = courseMapWithIdKey.get(option.class_reference);
if (option.type === 'course' || option.type === 'other') {
// 'other' might be an improperly parsed course
// if it's not, `course` will be set to undefined so nothing will happen
const course =
option.type === 'course'
? courseMapWithIdKey.get(option.class_reference)
: option.description.match(re)?.[0];
if (course) {
const data = courseHash.get(course as string);
if (data === undefined) {
Expand All @@ -171,8 +182,6 @@ export const validatorRouter = router({
} else {
count++;
}
} else if (option.type === 'other') {
// count++;
}
}
if (count >= requirements.required) {
Expand All @@ -196,8 +205,13 @@ export const validatorRouter = router({
}
const temp: [Array<string>, number] = [[], 0];
for (const option of requirements.options) {
if (option.type === 'course') {
const course = courseMapWithIdKey.get(option.class_reference);
if (option.type === 'course' || option.type === 'other') {
// 'other' might be an improperly parsed course
// if it's not, `course` will be set to undefined so nothing will happen
const course =
option.type === 'course'
? courseMapWithIdKey.get(option.class_reference)
: option.description.match(re)?.[0];
if (course) {
const data = courseHash.get(course as string);
if (data === undefined) {
Expand All @@ -217,8 +231,6 @@ export const validatorRouter = router({
} else {
count++;
}
} else if (option.type === 'other') {
// count++;
}
}
if (count >= requirements.required) {
Expand Down

1 comment on commit 9796da9

@vercel
Copy link

@vercel vercel bot commented on 9796da9 Apr 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

planner – ./

planner-git-release-10-utdnebula.vercel.app
planner.utdnebula.com
planner-utdnebula.vercel.app

Please sign in to comment.