File tree Expand file tree Collapse file tree 3 files changed +10
-12
lines changed
Expand file tree Collapse file tree 3 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 11-- $1 = senderId
22SELECT
3- recv ,
3+ * ,
44 -- course overlap
55 (SELECT COUNT (1 ) FROM " Course" course
66 WHERE EXISTS (SELECT 1 FROM " Enrollment" e WHERE e." courseId" = course .id AND e." userId" = recv .id )
Original file line number Diff line number Diff line change @@ -8,14 +8,14 @@ beforeAll(() => {
88
99test ( "recommendation engine" , async ( ) => {
1010 const usersFor101 = await recommendedTo ( 101 , 5 , 0 ) ;
11- if ( ! usersFor101 . ok ) throw new Error ( ) ;
11+ if ( ! usersFor101 . ok ) throw console . error ( usersFor101 . error ) ;
1212 expect ( usersFor101 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 102 , 103 ] ) ;
1313
1414 const usersFor102 = await recommendedTo ( 102 , 5 , 0 ) ;
15- if ( ! usersFor102 . ok ) throw new Error ( ) ;
15+ if ( ! usersFor102 . ok ) throw console . error ( usersFor102 . error ) ;
1616 expect ( usersFor102 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 103 , 101 ] ) ;
1717
1818 const usersFor103 = await recommendedTo ( 103 , 5 , 0 ) ;
19- if ( ! usersFor103 . ok ) throw new Error ( ) ;
19+ if ( ! usersFor103 . ok ) throw console . error ( usersFor103 . error ) ;
2020 expect ( usersFor103 . value . map ( ( entry ) => entry . u . id ) ) . toEqual ( [ 102 , 101 ] ) ;
2121} ) ;
Original file line number Diff line number Diff line change @@ -12,25 +12,23 @@ export async function recommendedTo(
1212 Result <
1313 Array < {
1414 u : UserWithCoursesAndSubjects ;
15- count : number ;
15+ overlap : number ;
1616 } >
1717 >
1818> {
1919 try {
2020 const result = await prisma . $queryRawTyped ( sql ( user , limit , offset ) ) ;
2121 return Promise . all (
2222 result . map ( async ( res ) => {
23- const user = await getUserByID ( res . id ) ;
24- if ( ! user . ok ) throw new Error ( "not found" ) ; // this shouldn't happen
25- return {
26- count : Number . parseInt ( res . overlap ?. toString ( ) ?? "0" ) ,
27- u : user . value ,
28- } ;
23+ if ( ! res ) throw new Error ( "res is null: something is wrong" ) ;
24+ const { overlap : count , ...u } = res ;
25+ return { count, u } ;
2926 } ) ,
3027 )
3128 . then ( ( val ) => Ok ( val ) )
3229 . catch ( ( err ) => Err ( err ) ) ;
3330 } catch ( err ) {
34- return Err ( err ) ;
31+ console . error ( "caught error: " , err ) ;
32+ return Err ( 500 ) ;
3533 }
3634}
You can’t perform that action at this time.
0 commit comments