Skip to content

Commit f184a01

Browse files
author
ruiichen
committed
fsm changes
1 parent 4c55845 commit f184a01

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,13 +1,19 @@
1+
import { Op } from "sequelize";
12
import {
23
PositionTitle,
34
ReviewDashboardRowDTO,
45
ReviewedApplicantRecordDTO,
6+
EngineeringPositionTitles,
7+
DesignPositionTitles,
8+
ProductPositionTitles,
9+
CommunityPositionTitles,
510
ReviewDashboardSidePanelDTO,
611
} from "../../types";
712
import IReviewDashboardService from "../interfaces/IReviewDashboardService";
813
import { getErrorMessage } from "../../utilities/errorUtils";
914
import logger from "../../utilities/logger";
1015
import ApplicantRecord from "../../models/applicantRecord.model";
16+
import User from "../../models/user.model";
1117

1218
const Logger = logger(__filename);
1319

@@ -141,10 +147,8 @@ class ReviewDashboardService implements IReviewDashboardService {
141147

142148
async delegateReviewers(): Promise<ReviewedApplicantRecordDTO[]> {
143149
// NOTE: We do not have to concern ourselves with locality. That is, each user can be
144-
// assigned to the same parter every time.
150+
// assigned to the same partner every time.
145151

146-
const FSM = new Map<string, [number, string[]]>();
147-
// maps (position title) => (current index of list, list of users with position_title)
148152
const delegations = new Map<string, [string, string]>();
149153
// maps (applicant_record_id) => pair of user_ids assigned to it
150154

@@ -153,6 +157,33 @@ class ReviewDashboardService implements IReviewDashboardService {
153157
// NOTE: need to add a sentinel value at the end of the list if the number of user is odd.
154158
// The last 'real' user will bear the burden of solo reviewing.
155159

160+
// Get users and group by position
161+
const groups = (
162+
await User.findAll({
163+
where: { position: { [Op.ne]: null } },
164+
})
165+
).reduce((map, user) => {
166+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
167+
const pos = user.position!;
168+
const arr = map.get(pos) ?? [];
169+
arr.push(user.id.toString());
170+
map.set(pos, arr);
171+
return map;
172+
}, new Map<string, string[]>());
173+
174+
// Build FSM
175+
// maps (position title) => (current index of list, list of users with position_title)
176+
const FSM = new Map<string, [number, string[]]>(
177+
[
178+
...EngineeringPositionTitles,
179+
...DesignPositionTitles,
180+
...ProductPositionTitles,
181+
...CommunityPositionTitles,
182+
].map((title) => [title, [0, groups.get(title) ?? []]]),
183+
);
184+
185+
// Modify FSM for correctness
186+
156187
// STEP 2:
157188
// Round robin with the FSM
158189
/*

0 commit comments

Comments
 (0)