@@ -77,6 +77,9 @@ export const validatorRouter = router({
7777 const coReqHash = new Map < string , Array < [ Array < string > , number ] > > ( ) ;
7878 const preReqHash = new Map < string , Array < [ Array < string > , number ] > > ( ) ;
7979 const coOrPreReqHash = new Map < string , Array < [ Array < string > , number ] > > ( ) ;
80+ // Regex to parse course from description of improperly parsed course
81+ const re = / \b [ A - Z ] { 2 , 4 } \d { 4 } \b / ;
82+
8083 /* Recursive function to check for prereqs.
8184 * TODO: Move to a client side function. Possibly a hook.
8285 */
@@ -105,8 +108,13 @@ export const validatorRouter = router({
105108 }
106109 const temp : [ Array < string > , number ] = [ [ ] , 0 ] ;
107110 for ( const option of requirements . options ) {
108- if ( option . type === 'course' ) {
109- const course = courseMapWithIdKey . get ( option . class_reference ) ;
111+ if ( option . type === 'course' || option . type === 'other' ) {
112+ // 'other' might be an improperly parsed course
113+ // if it's not, `course` will be set to undefined so nothing will happen
114+ const course =
115+ option . type === 'course'
116+ ? courseMapWithIdKey . get ( option . class_reference )
117+ : option . description . match ( re ) ?. [ 0 ] ;
110118 if ( course ) {
111119 const data = courseHash . get ( course as string ) ;
112120 if ( data === undefined ) {
@@ -124,8 +132,6 @@ export const validatorRouter = router({
124132 } else {
125133 count ++ ;
126134 }
127- } else if ( option . type === 'other' ) {
128- // count++;
129135 }
130136 }
131137
@@ -150,8 +156,13 @@ export const validatorRouter = router({
150156 }
151157 const temp : [ Array < string > , number ] = [ [ ] , 0 ] ;
152158 for ( const option of requirements . options ) {
153- if ( option . type === 'course' ) {
154- const course = courseMapWithIdKey . get ( option . class_reference ) ;
159+ if ( option . type === 'course' || option . type === 'other' ) {
160+ // 'other' might be an improperly parsed course
161+ // if it's not, `course` will be set to undefined so nothing will happen
162+ const course =
163+ option . type === 'course'
164+ ? courseMapWithIdKey . get ( option . class_reference )
165+ : option . description . match ( re ) ?. [ 0 ] ;
155166 if ( course ) {
156167 const data = courseHash . get ( course as string ) ;
157168 if ( data === undefined ) {
@@ -171,8 +182,6 @@ export const validatorRouter = router({
171182 } else {
172183 count ++ ;
173184 }
174- } else if ( option . type === 'other' ) {
175- // count++;
176185 }
177186 }
178187 if ( count >= requirements . required ) {
@@ -196,8 +205,13 @@ export const validatorRouter = router({
196205 }
197206 const temp : [ Array < string > , number ] = [ [ ] , 0 ] ;
198207 for ( const option of requirements . options ) {
199- if ( option . type === 'course' ) {
200- const course = courseMapWithIdKey . get ( option . class_reference ) ;
208+ if ( option . type === 'course' || option . type === 'other' ) {
209+ // 'other' might be an improperly parsed course
210+ // if it's not, `course` will be set to undefined so nothing will happen
211+ const course =
212+ option . type === 'course'
213+ ? courseMapWithIdKey . get ( option . class_reference )
214+ : option . description . match ( re ) ?. [ 0 ] ;
201215 if ( course ) {
202216 const data = courseHash . get ( course as string ) ;
203217 if ( data === undefined ) {
@@ -217,8 +231,6 @@ export const validatorRouter = router({
217231 } else {
218232 count ++ ;
219233 }
220- } else if ( option . type === 'other' ) {
221- // count++;
222234 }
223235 }
224236 if ( count >= requirements . required ) {
0 commit comments