Skip to content

Commit 04a0c10

Browse files
author
ruiichen
committed
fsm changes
1 parent b076dd8 commit 04a0c10

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

backend/typescript/services/implementations/reviewDashboardService.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import { Op } from "sequelize";
12
import {
23
PositionTitle,
34
ReviewDashboardRowDTO,
45
ReviewedApplicantRecordDTO,
6+
EngineeringPositionTitles,
7+
DesignPositionTitles,
8+
ProductPositionTitles,
9+
CommunityPositionTitles,
510
} from "../../types";
611
import IReviewDashboardService from "../interfaces/IReviewDashboardService";
712
import { getErrorMessage } from "../../utilities/errorUtils";
813
import logger from "../../utilities/logger";
914
import ApplicantRecord from "../../models/applicantRecord.model";
15+
import User from "../../models/user.model";
1016

1117
const 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

Comments
 (0)