Skip to content

Commit 69ee274

Browse files
committed
add endpoint for setting reviewerHasConflict to true
1 parent 3ce3feb commit 69ee274

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

backend/typescript/graphql/resolvers/reviewPageResolvers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
1+
import { ApplicationDTO, ReviewedApplicantRecordDTO, ReviewedApplicantsDTO } from "../../types";
22
import ReviewPageService from "../../services/implementations/reviewPageService";
33
import { getErrorMessage } from "../../utilities/errorUtils";
44

@@ -29,6 +29,18 @@ const reviewPageResolvers = {
2929
}
3030
},
3131
},
32+
Mutation: {
33+
reportReviewConflict: async (
34+
_parent: undefined,
35+
args: { applicantRecordId: string, reviewerId: number },
36+
): Promise<ReviewedApplicantRecordDTO> => {
37+
try {
38+
return await reviewPageService.reportReviewConflict(args.applicantRecordId, args.reviewerId);
39+
} catch (error) {
40+
throw new Error(getErrorMessage(error));
41+
}
42+
},
43+
},
3244
};
3345

3446
export default reviewPageResolvers;

backend/typescript/graphql/types/reviewPageType.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ const reviewPageType = gql`
3232
applicantLastName: String!
3333
}
3434
35+
type ReviewedApplicantRecordDTO {
36+
applicantRecordId: String!
37+
reviewerId: Int!
38+
review: Review!
39+
status: String!
40+
score: Int
41+
reviewerHasConflict: Boolean!
42+
}
43+
44+
extend type Mutation {
45+
reportReviewConflict(applicantRecordId: String!, reviewerId: String!): ReviewedApplicantRecordDTO!
46+
}
47+
3548
extend type Query {
3649
reviewApplicantPage(applicantRecordId: String!): ApplicationDTO!
3750
getReviewedApplicantsByUserId(userId: Int!): [ReviewedApplicantsDTO!]!

backend/typescript/services/implementations/reviewPageService.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
1+
import { ApplicationDTO, ReviewedApplicantRecordDTO, ReviewedApplicantsDTO } from "../../types";
22
import IReviewPageService from "../interfaces/IReviewPageService";
33
import { getErrorMessage } from "../../utilities/errorUtils";
44
import logger from "../../utilities/logger";
55
import ApplicantRecord from "../../models/applicantRecord.model";
6-
import type ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
6+
import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
77
import Applicant from "../../models/applicant.model";
88
import User from "../../models/user.model";
99

@@ -39,7 +39,7 @@ function toApplicationDTO(model: Applicant): ApplicationDTO {
3939
};
4040
}
4141

42-
function toReviewedApplicantRecordDTO(
42+
function toReviewedApplicantsDTO(
4343
model: ReviewedApplicantRecord,
4444
): ReviewedApplicantsDTO {
4545
/* eslint-disable @typescript-eslint/no-non-null-assertion */
@@ -51,6 +51,18 @@ function toReviewedApplicantRecordDTO(
5151
};
5252
}
5353

54+
function toReviewedApplicantRecordDTO(
55+
model: ReviewedApplicantRecord,
56+
): ReviewedApplicantRecordDTO {
57+
return {
58+
applicantRecordId: model.applicantRecordId,
59+
reviewerId: model.reviewerId,
60+
review: model.review,
61+
status: model.status,
62+
reviewerHasConflict: model.reviewerHasConflict,
63+
};
64+
}
65+
5466
class ReviewPageService implements IReviewPageService {
5567
/* eslint-disable class-methods-use-this */
5668
async getReviewPage(applicantRecordId: string): Promise<ApplicationDTO> {
@@ -110,12 +122,28 @@ class ReviewPageService implements IReviewPageService {
110122
});
111123
if (!user) throw new Error(`No user with ${userId} found.`);
112124
if (!user.reviewedApplicantRecords) return [];
113-
return user.reviewedApplicantRecords.map(toReviewedApplicantRecordDTO);
125+
return user.reviewedApplicantRecords.map(toReviewedApplicantsDTO);
114126
} catch (error: unknown) {
115127
Logger.error(`Failed to fetch. Reason = ${getErrorMessage(error)}`);
116128
throw error;
117129
}
118130
}
131+
132+
async reportReviewConflict(applicantRecordId: string, reviewerId: number): Promise<ReviewedApplicantRecordDTO> {
133+
try {
134+
const reviewedApplicantRecord: ReviewedApplicantRecord | null = await ReviewedApplicantRecord.findOne({
135+
where: { applicantRecordId, reviewerId },
136+
});
137+
if (!reviewedApplicantRecord) throw new Error(`No reviewed applicant record with ${applicantRecordId} and ${reviewerId} found.`);
138+
reviewedApplicantRecord.reviewerHasConflict = true;
139+
await reviewedApplicantRecord.save();
140+
return toReviewedApplicantRecordDTO(reviewedApplicantRecord);
141+
}
142+
catch (error: unknown) {
143+
Logger.error(`Failed to report conflict. Reason = ${getErrorMessage(error)}`);
144+
throw error;
145+
}
146+
}
119147
}
120148

121149
export default ReviewPageService;

backend/typescript/services/interfaces/IReviewPageService.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApplicationDTO, ReviewedApplicantsDTO } from "../../types";
1+
import { ApplicationDTO, ReviewedApplicantRecordDTO, ReviewedApplicantsDTO } from "../../types";
22

33
interface IReviewPageService {
44
/**
@@ -14,6 +14,13 @@ interface IReviewPageService {
1414
getReviewedApplicantsByUserId(
1515
userId: number,
1616
): Promise<ReviewedApplicantsDTO[]>;
17+
18+
/**
19+
* Update the reviewerHasConflict column of a ReviewedApplicantRecord entry to indicate a conflict.
20+
* @param applicantRecordId the id of the applicant record that the reviewer is interested in
21+
* @param reviewerId the id of the reviewer that is reporting the conflict
22+
*/
23+
reportReviewConflict(applicantRecordId: string, reviewerId: number): Promise<ReviewedApplicantRecordDTO>;
1724
}
1825

1926
export default IReviewPageService;

0 commit comments

Comments
 (0)