Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ const reviewedApplicantRecordResolvers = {
throw new Error(getErrorMessage(error));
}
},

reassignReviewedApplicantRecord: async (
_parent: undefined,
args: {
applicantRecordId: string;
oldReviewerId: number;
newReviewerId: number;
},
): Promise<ReviewedApplicantRecordDTO> => {
try {
return await reviewedApplicantRecordService.reassignReviewedApplicantRecord(
args.applicantRecordId,
args.oldReviewerId,
args.newReviewerId,
);
} catch (error) {
throw new Error(getErrorMessage(error));
}
},
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ const reviewedApplicantRecordTypes = gql`
bulkDeleteReviewedApplicantRecord(
inputs: [DeleteReviewedApplicantRecord!]!
): [ReviewedApplicantRecord!]!

reassignReviewedApplicantRecord(
applicantRecordId: ID!
oldReviewerId: Int!
newReviewerId: Int!
): ReviewedApplicantRecord!
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,51 @@ class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
throw error;
}
}

async reassignReviewedApplicantRecord(
applicantRecordId: string,
oldReviewerId: number,
newReviewerId: number,
): Promise<ReviewedApplicantRecordDTO> {
try {
return await sequelize.transaction(async (t) => {
const oldRecord = await ReviewedApplicantRecord.findOne({
where: { applicantRecordId, reviewerId: oldReviewerId },
transaction: t,
});

if (!oldRecord) {
throw new Error(
`ReviewedApplicantRecord not found for applicantRecordId: ${applicantRecordId} and reviewerId: ${oldReviewerId}`,
);
}

const oldRecordData = oldRecord.toJSON() as ReviewedApplicantRecordDTO;

await oldRecord.destroy({ transaction: t });

const newRecord = await ReviewedApplicantRecord.create(
{
applicantRecordId,
reviewerId: newReviewerId,
review: oldRecordData.review,
status: oldRecordData.status,
reviewerHasConflict: false,
},
{ transaction: t },
);

return newRecord.toJSON() as ReviewedApplicantRecordDTO;
});
} catch (error: unknown) {
Logger.error(
`Failed to reassign reviewed applicant record. Reason = ${getErrorMessage(
error,
)}`,
);
throw error;
}
}
}

export default ReviewedApplicantRecordService;
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ interface IReviewApplicantRecordService {
bulkDeleteReviewedApplicantRecord(
deleteReviewedApplicantRecords: DeleteReviewedApplicantRecordDTO[],
): Promise<ReviewedApplicantRecordDTO[]>;

/**
* Reassigns a reviewed applicant record from one reviewer to another
* @Param applicantRecordId the ID of applicant record to reassign
* @Param oldReviewerId the ID of the current reviewer
* @Param newReviewerId the ID of the new reviewer
*/
reassignReviewedApplicantRecord(
applicantRecordId: string,
oldReviewerId: number,
newReviewerId: number,
): Promise<ReviewedApplicantRecordDTO>;
}

export default IReviewApplicantRecordService;
Loading