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
4 changes: 4 additions & 0 deletions backend/typescript/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import reviewDashboardResolvers from "./resolvers/reviewDashboardResolvers";
import reviewDashboardType from "./types/reviewDashboardType";
import adminCommentResolvers from "./resolvers/adminCommentsResolvers";
import adminCommentType from "./types/adminCommentsType";
import applicantRecordResolvers from "./resolvers/applicantRecordResolvers";
import applicantRecordType from "./types/applicantRecordType";
import reviewPageType from "./types/reviewPageType";
import reviewPageResolvers from "./resolvers/reviewPageResolvers";

Expand All @@ -44,6 +46,7 @@ const executableSchema = makeExecutableSchema({
userType,
reviewDashboardType,
adminCommentType,
applicantRecordType,
reviewPageType,
],
resolvers: merge(
Expand All @@ -53,6 +56,7 @@ const executableSchema = makeExecutableSchema({
userResolvers,
reviewDashboardResolvers,
adminCommentResolvers,
applicantRecordResolvers,
reviewPageResolvers,
),
});
Expand Down
32 changes: 32 additions & 0 deletions backend/typescript/graphql/resolvers/applicantRecordResolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ApplicantRecordService from "../../services/implementations/applicantRecordService";
import IApplicantRecordService from "../../services/interfaces/applicantRecordService";
import { ApplicantRecordDTO } from "../../types";
import { getErrorMessage } from "../../utilities/errorUtils";

const applicantRecordService: IApplicantRecordService =
new ApplicantRecordService();

const applicantRecordResolvers = {
Mutation: {
setApplicantRecordFlag: async (
_parent: undefined,
{
applicantRecordId,
flagValue,
}: { applicantRecordId: string; flagValue: boolean },
): Promise<ApplicantRecordDTO> => {
try {
const applicantRecord =
await applicantRecordService.setApplicantRecordFlag(
applicantRecordId,
flagValue,
);
return applicantRecord;
} catch (error: unknown) {
throw new Error(getErrorMessage(error));
}
},
},
};

export default applicantRecordResolvers;
24 changes: 24 additions & 0 deletions backend/typescript/graphql/types/applicantRecordType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { gql } from "apollo-server-express";

const applicantRecordType = gql`
type ApplicantRecordDTO {
id: String!
applicantId: String!
position: String!
roleSpecificQuestions: [String!]!
choice: Int!
status: String!
skillCategory: String
combined_score: Int
isApplicantFlagged: Boolean!
}
extend type Mutation {
setApplicantRecordFlag(
applicantRecordId: String!
flagValue: Boolean!
): ApplicantRecordDTO!
}
`;

export default applicantRecordType;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DataType } from "sequelize-typescript";
import { Migration } from "../umzug";

const TABLE_NAME = "applicant_records";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "createdAt", {
type: DataType.DATE,
allowNull: false,
defaultValue: new Date(),
});
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "updatedAt", {
type: DataType.DATE,
allowNull: false,
defaultValue: new Date(),
});
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "createdAt");
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "updatedAt");
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { ApplicantRecordDTO, PositionTitle } from "../../types";
import { getErrorMessage } from "../../utilities/errorUtils";
import logger from "../../utilities/logger";
import ApplicantRecord from "../../models/applicantRecord.model";
import IApplicantRecordService from "../interfaces/applicantRecordService";

const Logger = logger(__filename);

class ApplicantRecordService implements IApplicantRecordService {
/* eslint-disable class-methods-use-this */
async setApplicantRecordFlag(
applicantRecordId: string,
flagValue: boolean,
): Promise<ApplicantRecordDTO> {
try {
const applicantRecord = await ApplicantRecord.findByPk(applicantRecordId);
if (!applicantRecord) {
throw new Error(
`ApplicantRecord with id ${applicantRecordId} not found.`,
);
}
applicantRecord.isApplicantFlagged = flagValue;
await applicantRecord.save();
return {
id: String(applicantRecord.id),
applicantId: String(applicantRecord.applicantId),
position: applicantRecord.position as PositionTitle,
roleSpecificQuestions: applicantRecord.roleSpecificQuestions,
choice: applicantRecord.choice,
status: applicantRecord.status,
skillCategory: applicantRecord.skillCategory,
combined_score: applicantRecord.combined_score,
isApplicantFlagged: applicantRecord.isApplicantFlagged,
};
} catch (error: unknown) {
Logger.error(
`Failed to set applicant record flag. Reason = ${getErrorMessage(
error,
)}`,
);
throw error;
}
}
}

export default ApplicantRecordService;
10 changes: 10 additions & 0 deletions backend/typescript/services/interfaces/applicantRecordService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApplicantRecordDTO } from "../../types";

interface IApplicantRecordService {
setApplicantRecordFlag(
applicantRecordId: string,
flagValue: boolean,
): Promise<ApplicantRecordDTO>;
}

export default IApplicantRecordService;
3 changes: 2 additions & 1 deletion backend/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ export type ApplicantDTO = {
};

export type ApplicantRecordDTO = {
id: number;
id: string;
applicantId: string;
position: PositionTitle; // EDIT LATER
roleSpecificQuestions: string[];
choice: number;
status: ApplicationStatus;
skillCategory?: SkillCategory;
combined_score?: number | null;
isApplicantFlagged: boolean;
};

export type ApplicationStatus =
Expand Down
Loading