Skip to content

Commit a00b1cb

Browse files
committed
created helper
1 parent 3d65136 commit a00b1cb

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

backend/typescript/services/implementations/reviewDashboardService.ts

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ function toDTO(model: ApplicantRecord): ReviewDashboardRowDTO {
2626
};
2727
}
2828

29+
function toSidePanelDTO(model: ApplicantRecord): ReviewDashboardSidePanelDTO {
30+
const reviewDetails =
31+
model.reviewedApplicantRecords?.map((reviewRecord) => ({
32+
reviewerFirstName: reviewRecord.user?.first_name || "",
33+
reviewerLastName: reviewRecord.user?.last_name || "",
34+
review: reviewRecord.review,
35+
})) || [];
36+
37+
return {
38+
firstName: model.applicant!.firstName,
39+
lastName: model.applicant!.lastName,
40+
positionTitle: model.position as PositionTitle,
41+
program: model.applicant!.program,
42+
resumeUrl: model.applicant!.resumeUrl,
43+
applicationStatus: model.status,
44+
skillCategory: model.skillCategory || "Junior", // seems skill category can be null in the applicant record db right now
45+
reviewDetails: reviewDetails,
46+
};
47+
}
48+
2949
class ReviewDashboardService implements IReviewDashboardService {
3050
/* eslint-disable class-methods-use-this */
3151
async getReviewDashboard(
@@ -81,50 +101,33 @@ class ReviewDashboardService implements IReviewDashboardService {
81101
applicantId: string,
82102
): Promise<ReviewDashboardSidePanelDTO> {
83103
try {
84-
// Find the applicant record with all necessary joins
85-
const applicantRecord = await ApplicantRecord.findOne({
86-
where: { applicantId: applicantId },
87-
attributes: { exclude: ["createdAt", "updatedAt"] },
88-
include: [
89-
{
90-
attributes: { exclude: ["createdAt", "updatedAt"] },
91-
association: "applicant",
92-
},
93-
{
94-
attributes: { exclude: ["createdAt", "updatedAt"] },
95-
association: "reviewedApplicantRecords",
96-
include: [
97-
{
98-
attributes: { exclude: ["createdAt", "updatedAt"] },
99-
association: "user",
100-
},
101-
],
102-
},
103-
],
104-
});
104+
const applicantRecord: ApplicantRecord | null =
105+
await ApplicantRecord.findOne({
106+
where: { applicantId: applicantId },
107+
attributes: { exclude: ["createdAt", "updatedAt"] },
108+
include: [
109+
{
110+
attributes: { exclude: ["createdAt", "updatedAt"] },
111+
association: "reviewedApplicantRecords",
112+
include: [
113+
{
114+
attributes: { exclude: ["createdAt", "updatedAt"] },
115+
association: "user",
116+
},
117+
],
118+
},
119+
{
120+
attributes: { exclude: ["createdAt", "updatedAt"] },
121+
association: "applicant",
122+
},
123+
],
124+
});
105125

106126
if (!applicantRecord || !applicantRecord.applicant) {
107127
throw new Error(`Applicant with ID ${applicantId} not found`);
108128
}
109129

110-
// Transform the data to the required DTO format
111-
const reviewDetails =
112-
applicantRecord.reviewedApplicantRecords?.map((reviewRecord) => ({
113-
reviewerFirstName: reviewRecord.user?.first_name || "",
114-
reviewerLastName: reviewRecord.user?.last_name || "",
115-
review: reviewRecord.review,
116-
})) || [];
117-
118-
return {
119-
firstName: applicantRecord.applicant.firstName,
120-
lastName: applicantRecord.applicant.lastName,
121-
positionTitle: applicantRecord.position as PositionTitle,
122-
program: applicantRecord.applicant.program,
123-
resumeUrl: applicantRecord.applicant.resumeUrl,
124-
applicationStatus: applicantRecord.status,
125-
skillCategory: applicantRecord.skillCategory || "Junior",
126-
reviewDetails: reviewDetails,
127-
};
130+
return toSidePanelDTO(applicantRecord);
128131
} catch (error: unknown) {
129132
Logger.error(
130133
`Failed to get review dashboard side panel for applicant ${applicantId}. Reason = ${getErrorMessage(

0 commit comments

Comments
 (0)