@@ -149,7 +149,7 @@ class ReviewDashboardService implements IReviewDashboardService {
149149 // NOTE: We do not have to concern ourselves with locality. That is, each user can be
150150 // assigned to the same partner every time.
151151
152- const delegations = new Map < string , [ string , string ] > ( ) ;
152+ const delegations = new Map < string , [ string , string | undefined ] > ( ) ;
153153 // maps (applicant_record_id) => pair of user_ids assigned to it
154154
155155 // STEP 1:
@@ -160,6 +160,7 @@ class ReviewDashboardService implements IReviewDashboardService {
160160 // Get users and group by position
161161 const groups = (
162162 await User . findAll ( {
163+ attributes : { exclude : [ "createdAt" , "updatedAt" ] } ,
163164 where : { position : { [ Op . ne ] : null } } ,
164165 } )
165166 ) . reduce ( ( map , user ) => {
@@ -173,7 +174,7 @@ class ReviewDashboardService implements IReviewDashboardService {
173174
174175 // Build FSM
175176 // maps (position title) => (current index of list, list of users with position_title)
176- const FSM = new Map < string , [ number , string [ ] ] > (
177+ const FSM = new Map < string , [ number , ( string | undefined ) [ ] ] > (
177178 [
178179 ...EngineeringPositionTitles ,
179180 ...DesignPositionTitles ,
@@ -182,7 +183,17 @@ class ReviewDashboardService implements IReviewDashboardService {
182183 ] . map ( ( title ) => [ title , [ 0 , groups . get ( title ) ?? [ ] ] ] ) ,
183184 ) ;
184185
185- // Modify FSM for correctness
186+ // Validate FSM for correctness
187+ Array . from ( FSM . entries ( ) ) . forEach ( ( [ title , [ , userIds ] ] ) => {
188+ if ( userIds . length === 0 ) {
189+ // no users with this position
190+ throw new Error ( `Invalid amount of users with position ${ title } .` ) ;
191+ }
192+ if ( userIds . length % 2 !== 0 ) {
193+ // sentinel value of undefined at the end
194+ userIds . push ( undefined ) ;
195+ }
196+ } ) ;
186197
187198 // STEP 2:
188199 // Round robin with the FSM
@@ -203,6 +214,31 @@ class ReviewDashboardService implements IReviewDashboardService {
203214 delegations[a.id] = make_pair(id1, id2);
204215 }
205216 */
217+ const applicantRecords = await ApplicantRecord . findAll ( {
218+ attributes : { exclude : [ "createdAt" , "updatedAt" ] } ,
219+ } ) ;
220+ applicantRecords . forEach ( ( record ) => {
221+ /* eslint-disable @typescript-eslint/no-non-null-assertion */
222+ const [ count , userIds ] = FSM . get ( record . position ) ! ;
223+ let newCount = count ;
224+ const assignedReviewer1 = FSM . get ( record . position ) ! [ 1 ] [ newCount ] ;
225+ newCount ++ ;
226+ newCount %= FSM . get ( record . position ) ! [ 1 ] . length ;
227+ const assignedReviewer2 = FSM . get ( record . position ) ! [ 1 ] [ newCount ] ;
228+ newCount ++ ;
229+ newCount %= FSM . get ( record . position ) ! [ 1 ] . length ;
230+ FSM . set ( record . position , [ newCount , userIds ] ) ;
231+ delegations . set ( record . id , [ assignedReviewer1 ! , assignedReviewer2 ] ) ;
232+ /* eslint-enable @typescript-eslint/no-non-null-assertion */
233+ if ( record . position === "Developer" ) {
234+ console . log (
235+ `Assigned reviewers for applicant ${ record . id } (${ record . position } ):` ,
236+ assignedReviewer1 ,
237+ "and" ,
238+ assignedReviewer2 ,
239+ ) ;
240+ }
241+ } ) ;
206242
207243 // STEP 3:
208244 // Batch the delegations into ReviewedApplicantRecords
0 commit comments