@@ -7,15 +7,19 @@ import {
77 DesignPositionTitles ,
88 ProductPositionTitles ,
99 CommunityPositionTitles ,
10+ CreateReviewedApplicantRecordDTO ,
1011} from "../../types" ;
1112import IReviewDashboardService from "../interfaces/IReviewDashboardService" ;
1213import { getErrorMessage } from "../../utilities/errorUtils" ;
1314import logger from "../../utilities/logger" ;
1415import ApplicantRecord from "../../models/applicantRecord.model" ;
1516import User from "../../models/user.model" ;
17+ import ReviewedApplicantRecordService from "./reviewedApplicantRecordService" ;
1618
1719const Logger = logger ( __filename ) ;
1820
21+ const reviewedApplicantRecordService = new ReviewedApplicantRecordService ( ) ;
22+
1923function toDTO ( model : ApplicantRecord ) : ReviewDashboardRowDTO {
2024 return {
2125 firstName : model . applicant ! . firstName ,
@@ -83,11 +87,13 @@ class ReviewDashboardService implements IReviewDashboardService {
8387 }
8488 }
8589
86- async delegateReviewers ( ) : Promise < ReviewedApplicantRecordDTO [ ] > {
90+ async delegateReviewers (
91+ positions : string [ ] ,
92+ ) : Promise < ReviewedApplicantRecordDTO [ ] > {
8793 // NOTE: We do not have to concern ourselves with locality. That is, each user can be
8894 // assigned to the same partner every time.
8995
90- const delegations = new Map < string , [ string , string | undefined ] > ( ) ;
96+ const delegations = Array < CreateReviewedApplicantRecordDTO > ( ) ;
9197 // maps (applicant_record_id) => pair of user_ids assigned to it
9298
9399 // STEP 1:
@@ -105,14 +111,14 @@ class ReviewDashboardService implements IReviewDashboardService {
105111 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
106112 const pos = user . position ! ;
107113 const arr = map . get ( pos ) ?? [ ] ;
108- arr . push ( user . id . toString ( ) ) ;
114+ arr . push ( user . id ) ;
109115 map . set ( pos , arr ) ;
110116 return map ;
111- } , new Map < string , string [ ] > ( ) ) ;
117+ } , new Map < string , number [ ] > ( ) ) ;
112118
113119 // Build FSM
114120 // maps (position title) => (current index of list, list of users with position_title)
115- const FSM = new Map < string , [ number , ( string | undefined ) [ ] ] > (
121+ const FSM = new Map < string , [ number , ( number | undefined ) [ ] ] > (
116122 [
117123 ...EngineeringPositionTitles ,
118124 ...DesignPositionTitles ,
@@ -166,23 +172,29 @@ class ReviewDashboardService implements IReviewDashboardService {
166172 newCount ++ ;
167173 newCount %= FSM . get ( record . position ) ! [ 1 ] . length ;
168174 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- ) ;
175+
176+ if ( assignedReviewer1 !== undefined ) {
177+ delegations . push ( {
178+ applicantRecordId : record . id ,
179+ reviewerId : assignedReviewer1 ,
180+ } ) ;
181+ }
182+
183+ if ( assignedReviewer2 !== undefined ) {
184+ delegations . push ( {
185+ applicantRecordId : record . id ,
186+ reviewerId : assignedReviewer2 ,
187+ } ) ;
178188 }
179189 } ) ;
180190
181191 // STEP 3:
182192 // Batch the delegations into ReviewedApplicantRecords
183193 // NOTE: do not add the sentinel value we inserted earlier.
184-
185- return [ ] ;
194+ console . log ( delegations ) ;
195+ return reviewedApplicantRecordService . bulkCreateReviewedApplicantRecord (
196+ delegations ,
197+ ) ;
186198 }
187199}
188200
0 commit comments