1+ import { Op } from "sequelize" ;
12import {
23 PositionTitle ,
34 ReviewDashboardRowDTO ,
45 ReviewedApplicantRecordDTO ,
6+ EngineeringPositionTitles ,
7+ DesignPositionTitles ,
8+ ProductPositionTitles ,
9+ CommunityPositionTitles ,
510} from "../../types" ;
611import IReviewDashboardService from "../interfaces/IReviewDashboardService" ;
712import { getErrorMessage } from "../../utilities/errorUtils" ;
813import logger from "../../utilities/logger" ;
914import ApplicantRecord from "../../models/applicantRecord.model" ;
15+ import User from "../../models/user.model" ;
1016
1117const Logger = logger ( __filename ) ;
1218
@@ -79,10 +85,8 @@ class ReviewDashboardService implements IReviewDashboardService {
7985
8086 async delegateReviewers ( ) : Promise < ReviewedApplicantRecordDTO [ ] > {
8187 // NOTE: We do not have to concern ourselves with locality. That is, each user can be
82- // assigned to the same parter every time.
88+ // assigned to the same partner every time.
8389
84- const FSM = new Map < string , [ number , string [ ] ] > ( ) ;
85- // maps (position title) => (current index of list, list of users with position_title)
8690 const delegations = new Map < string , [ string , string ] > ( ) ;
8791 // maps (applicant_record_id) => pair of user_ids assigned to it
8892
@@ -91,6 +95,33 @@ class ReviewDashboardService implements IReviewDashboardService {
9195 // NOTE: need to add a sentinel value at the end of the list if the number of user is odd.
9296 // The last 'real' user will bear the burden of solo reviewing.
9397
98+ // Get users and group by position
99+ const groups = (
100+ await User . findAll ( {
101+ where : { position : { [ Op . ne ] : null } } ,
102+ } )
103+ ) . reduce ( ( map , user ) => {
104+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
105+ const pos = user . position ! ;
106+ const arr = map . get ( pos ) ?? [ ] ;
107+ arr . push ( user . id . toString ( ) ) ;
108+ map . set ( pos , arr ) ;
109+ return map ;
110+ } , new Map < string , string [ ] > ( ) ) ;
111+
112+ // Build FSM
113+ // maps (position title) => (current index of list, list of users with position_title)
114+ const FSM = new Map < string , [ number , string [ ] ] > (
115+ [
116+ ...EngineeringPositionTitles ,
117+ ...DesignPositionTitles ,
118+ ...ProductPositionTitles ,
119+ ...CommunityPositionTitles ,
120+ ] . map ( ( title ) => [ title , [ 0 , groups . get ( title ) ?? [ ] ] ] ) ,
121+ ) ;
122+
123+ // Modify FSM for correctness
124+
94125 // STEP 2:
95126 // Round robin with the FSM
96127 /*
0 commit comments