Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion backend/typescript/graphql/resolvers/reviewPageResolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationDTO } from "../../types";
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
import ReviewPageService from "../../services/implementations/reviewPageService";
import { getErrorMessage } from "../../utilities/errorUtils";

Expand All @@ -16,6 +16,18 @@ const reviewPageResolvers = {
throw new Error(getErrorMessage(error));
}
},
getReviewedApplicantsByUserId: async (
_parent: undefined,
args: { userId: number },
): Promise<ReviewedApplicantsDTO[]> => {
try {
return await reviewPageService.getReviewedApplicantsByUserId(
args.userId,
);
} catch (error) {
throw new Error(getErrorMessage(error));
}
},
},
};

Expand Down
9 changes: 0 additions & 9 deletions backend/typescript/graphql/types/reviewDashboardType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ const reviewDashboardType = gql`
totalScore: Int
}
type Review {
passionFSG: Int
teamPlayer: Int
desireToLearn: Int
skill: Int
skillCategory: String
comments: String
}
type ReviewDetails {
reviewerFirstName: String!
reviewerLastName: String!
Expand Down
8 changes: 8 additions & 0 deletions backend/typescript/graphql/types/reviewPageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ const reviewPageType = gql`
timestamp: Int
}

type ReviewedApplicantsDTO {
applicantRecordId: String!
reviewStatus: String!
applicantFirstName: String!
applicantLastName: String!
}

extend type Query {
reviewApplicantPage(applicantRecordId: String!): ApplicationDTO!
getReviewedApplicantsByUserId(userId: Int!): [ReviewedApplicantsDTO!]!
}
`;

Expand Down
6 changes: 6 additions & 0 deletions backend/typescript/models/reviewedApplicantRecord.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ export default class ReviewedApplicantRecord extends Model {

@BelongsTo(() => User, { foreignKey: "reviewerId", targetKey: "id" })
user?: NonAttribute<User>;

@BelongsTo(() => ApplicantRecord, {
foreignKey: "applicantRecordId",
targetKey: "id",
})
applicantRecord?: NonAttribute<ApplicantRecord>;
}
2 changes: 1 addition & 1 deletion backend/typescript/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class User extends Model {

@HasMany(() => ReviewedApplicantRecord, {
foreignKey: "reviewerId",
as: "user",
sourceKey: "id",
})
reviewedApplicantRecords?: NonAttribute<ReviewedApplicantRecord[]>;
}
56 changes: 53 additions & 3 deletions backend/typescript/services/implementations/reviewPageService.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { ApplicationDTO } from "../../types";
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
import IReviewPageService from "../interfaces/IReviewPageService";
import { getErrorMessage } from "../../utilities/errorUtils";
import logger from "../../utilities/logger";
import ApplicantRecord from "../../models/applicantRecord.model";
import type ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
import Applicant from "../../models/applicant.model";
import User from "../../models/user.model";

const Logger = logger(__filename);

function toDTO(model: Applicant): ApplicationDTO {
function toApplicationDTO(model: Applicant): ApplicationDTO {
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const firstChoice = model.applicantRecords!.find((ar) => ar.choice === 1);
const secondChoice = model.applicantRecords!.find((ar) => ar.choice === 2);

Expand Down Expand Up @@ -36,6 +39,18 @@ function toDTO(model: Applicant): ApplicationDTO {
};
}

function toReviewedApplicantRecordDTO(
model: ReviewedApplicantRecord,
): ReviewedApplicantsDTO {
/* eslint-disable @typescript-eslint/no-non-null-assertion */
return {
applicantRecordId: model.applicantRecordId,
reviewStatus: model.status,
applicantFirstName: model.applicantRecord!.applicant!.firstName,
applicantLastName: model.applicantRecord!.applicant!.lastName,
};
}

class ReviewPageService implements IReviewPageService {
/* eslint-disable class-methods-use-this */
async getReviewPage(applicantRecordId: string): Promise<ApplicationDTO> {
Expand All @@ -60,7 +75,42 @@ class ReviewPageService implements IReviewPageService {
});
if (!applicant) throw new Error(`Database integrity has been violated`);

return toDTO(applicant);
return toApplicationDTO(applicant);
} catch (error: unknown) {
Logger.error(`Failed to fetch. Reason = ${getErrorMessage(error)}`);
throw error;
}
}

async getReviewedApplicantsByUserId(
userId: number,
): Promise<ReviewedApplicantsDTO[]> {
try {
const user: User | null = await User.findOne({
where: { id: userId },
attributes: { exclude: ["createdAt", "updatedAt"] },
include: [
{
attributes: { exclude: ["createdAt", "updatedAt"] },
association: "reviewedApplicantRecords",
include: [
{
attributes: { exclude: ["createdAt", "updatedAt"] },
association: "applicantRecord",
include: [
{
attributes: { exclude: ["createdAt", "updatedAt"] },
association: "applicant",
},
],
},
],
},
],
});
if (!user) throw new Error(`No user with ${userId} found.`);
if (!user.reviewedApplicantRecords) return [];
return user.reviewedApplicantRecords.map(toReviewedApplicantRecordDTO);
} catch (error: unknown) {
Logger.error(`Failed to fetch. Reason = ${getErrorMessage(error)}`);
throw error;
Expand Down
10 changes: 9 additions & 1 deletion backend/typescript/services/interfaces/IReviewPageService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { ApplicationDTO } from "../../types";
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";

interface IReviewPageService {
/**
* Fetch data from the Applicant and ApplicantRecord table to return an ApplicationDTO object
* @Param applicantRecordId the id of the applicant record that the viewer is interested in
*/
getReviewPage(applicantRecordId: string): Promise<ApplicationDTO>;

/**
* Fetches information about all the applicants assigned to a user to review
* @param userId the id of the user that the viewer is interested in
*/
getReviewedApplicantsByUserId(
userId: number,
): Promise<ReviewedApplicantsDTO[]>;
}

export default IReviewPageService;
7 changes: 7 additions & 0 deletions backend/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ export type ReviewDashboardSidePanelDTO = {
reviewDetails: ReviewDetails[];
};

export type ReviewedApplicantsDTO = {
applicantRecordId: string;
reviewStatus: ReviewStatus;
applicantFirstName: string;
applicantLastName: string;
};

export type AdminCommentDTO = {
id: string;
userId: number;
Expand Down
Loading