@@ -87,7 +87,7 @@ class ReviewDashboardService implements IReviewDashboardService {
8787 // NOTE: We do not have to concern ourselves with locality. That is, each user can be
8888 // assigned to the same partner every time.
8989
90- const delegations = new Map < string , [ string , string ] > ( ) ;
90+ const delegations = new Map < string , [ string , string | undefined ] > ( ) ;
9191 // maps (applicant_record_id) => pair of user_ids assigned to it
9292
9393 // STEP 1:
@@ -98,6 +98,7 @@ class ReviewDashboardService implements IReviewDashboardService {
9898 // Get users and group by position
9999 const groups = (
100100 await User . findAll ( {
101+ attributes : { exclude : [ "createdAt" , "updatedAt" ] } ,
101102 where : { position : { [ Op . ne ] : null } } ,
102103 } )
103104 ) . reduce ( ( map , user ) => {
@@ -111,7 +112,7 @@ class ReviewDashboardService implements IReviewDashboardService {
111112
112113 // Build FSM
113114 // maps (position title) => (current index of list, list of users with position_title)
114- const FSM = new Map < string , [ number , string [ ] ] > (
115+ const FSM = new Map < string , [ number , ( string | undefined ) [ ] ] > (
115116 [
116117 ...EngineeringPositionTitles ,
117118 ...DesignPositionTitles ,
@@ -120,7 +121,17 @@ class ReviewDashboardService implements IReviewDashboardService {
120121 ] . map ( ( title ) => [ title , [ 0 , groups . get ( title ) ?? [ ] ] ] ) ,
121122 ) ;
122123
123- // Modify FSM for correctness
124+ // Validate FSM for correctness
125+ Array . from ( FSM . entries ( ) ) . forEach ( ( [ title , [ , userIds ] ] ) => {
126+ if ( userIds . length === 0 ) {
127+ // no users with this position
128+ throw new Error ( `Invalid amount of users with position ${ title } .` ) ;
129+ }
130+ if ( userIds . length % 2 !== 0 ) {
131+ // sentinel value of undefined at the end
132+ userIds . push ( undefined ) ;
133+ }
134+ } ) ;
124135
125136 // STEP 2:
126137 // Round robin with the FSM
@@ -141,6 +152,31 @@ class ReviewDashboardService implements IReviewDashboardService {
141152 delegations[a.id] = make_pair(id1, id2);
142153 }
143154 */
155+ const applicantRecords = await ApplicantRecord . findAll ( {
156+ attributes : { exclude : [ "createdAt" , "updatedAt" ] } ,
157+ } ) ;
158+ applicantRecords . forEach ( ( record ) => {
159+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
160+ const [ count , userIds ] = FSM . get ( record . position ) ! ;
161+ let newCount = count ;
162+ const assignedReviewer1 = FSM . get ( record . position ) ! [ 1 ] [ newCount ] ;
163+ newCount ++ ;
164+ newCount %= FSM . get ( record . position ) ! [ 1 ] . length ;
165+ const assignedReviewer2 = FSM . get ( record . position ) ! [ 1 ] [ newCount ] ;
166+ newCount ++ ;
167+ newCount %= FSM . get ( record . position ) ! [ 1 ] . length ;
168+ FSM . set ( record . position , [ newCount , userIds ] ) ;
169+ delegations . set ( record . id , [ assignedReviewer1 ! , assignedReviewer2 ] ) ;
170+ /* eslint-enable @typescript-eslint/no-non-null-assertion */
171+ if ( record . position === "Developer" ) {
172+ console . log (
173+ `Assigned reviewers for applicant ${ record . id } (${ record . position } ):` ,
174+ assignedReviewer1 ,
175+ "and" ,
176+ assignedReviewer2 ,
177+ ) ;
178+ }
179+ } ) ;
144180
145181 // STEP 3:
146182 // Batch the delegations into ReviewedApplicantRecords
0 commit comments