@@ -7,16 +7,20 @@ import {
77 DesignPositionTitles ,
88 ProductPositionTitles ,
99 CommunityPositionTitles ,
10+ CreateReviewedApplicantRecordDTO ,
1011 ReviewDashboardSidePanelDTO ,
1112} from "../../types" ;
1213import IReviewDashboardService from "../interfaces/IReviewDashboardService" ;
1314import { getErrorMessage } from "../../utilities/errorUtils" ;
1415import logger from "../../utilities/logger" ;
1516import ApplicantRecord from "../../models/applicantRecord.model" ;
1617import User from "../../models/user.model" ;
18+ import ReviewedApplicantRecordService from "./reviewedApplicantRecordService" ;
1719
1820const Logger = logger ( __filename ) ;
1921
22+ const reviewedApplicantRecordService = new ReviewedApplicantRecordService ( ) ;
23+
2024function toDTO ( model : ApplicantRecord ) : ReviewDashboardRowDTO {
2125 return {
2226 firstName : model . applicant ! . firstName ,
@@ -145,11 +149,13 @@ class ReviewDashboardService implements IReviewDashboardService {
145149 }
146150 }
147151
148- async delegateReviewers ( ) : Promise < ReviewedApplicantRecordDTO [ ] > {
152+ async delegateReviewers (
153+ positions : string [ ] ,
154+ ) : Promise < ReviewedApplicantRecordDTO [ ] > {
149155 // NOTE: We do not have to concern ourselves with locality. That is, each user can be
150156 // assigned to the same partner every time.
151157
152- const delegations = new Map < string , [ string , string | undefined ] > ( ) ;
158+ const delegations = Array < CreateReviewedApplicantRecordDTO > ( ) ;
153159 // maps (applicant_record_id) => pair of user_ids assigned to it
154160
155161 // STEP 1:
@@ -167,14 +173,14 @@ class ReviewDashboardService implements IReviewDashboardService {
167173 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
168174 const pos = user . position ! ;
169175 const arr = map . get ( pos ) ?? [ ] ;
170- arr . push ( user . id . toString ( ) ) ;
176+ arr . push ( user . id ) ;
171177 map . set ( pos , arr ) ;
172178 return map ;
173- } , new Map < string , string [ ] > ( ) ) ;
179+ } , new Map < string , number [ ] > ( ) ) ;
174180
175181 // Build FSM
176182 // maps (position title) => (current index of list, list of users with position_title)
177- const FSM = new Map < string , [ number , ( string | undefined ) [ ] ] > (
183+ const FSM = new Map < string , [ number , ( number | undefined ) [ ] ] > (
178184 [
179185 ...EngineeringPositionTitles ,
180186 ...DesignPositionTitles ,
@@ -228,23 +234,29 @@ class ReviewDashboardService implements IReviewDashboardService {
228234 newCount ++ ;
229235 newCount %= FSM . get ( record . position ) ! [ 1 ] . length ;
230236 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- ) ;
237+
238+ if ( assignedReviewer1 !== undefined ) {
239+ delegations . push ( {
240+ applicantRecordId : record . id ,
241+ reviewerId : assignedReviewer1 ,
242+ } ) ;
243+ }
244+
245+ if ( assignedReviewer2 !== undefined ) {
246+ delegations . push ( {
247+ applicantRecordId : record . id ,
248+ reviewerId : assignedReviewer2 ,
249+ } ) ;
240250 }
241251 } ) ;
242252
243253 // STEP 3:
244254 // Batch the delegations into ReviewedApplicantRecords
245255 // NOTE: do not add the sentinel value we inserted earlier.
246-
247- return [ ] ;
256+ console . log ( delegations ) ;
257+ return reviewedApplicantRecordService . bulkCreateReviewedApplicantRecord (
258+ delegations ,
259+ ) ;
248260 }
249261}
250262
0 commit comments