Skip to content

Commit a627d46

Browse files
committed
add review status mutator
1 parent e010ca3 commit a627d46

File tree

5 files changed

+120
-8
lines changed

5 files changed

+120
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import ReviewedApplicantRecordService from "../../services/implementations/reviewedApplicantRecordService";
2+
import IReviewedApplicantRecordService from "../../services/interfaces/reviewedApplicantRecordService";
3+
import { ReviewedApplicantRecordDTO, ReviewStatus } from "../../types";
4+
5+
const reviewedApplicantRecordService: IReviewedApplicantRecordService = new ReviewedApplicantRecordService();
6+
7+
const reviewedApplicantRecordResolvers = {
8+
Mutation: {
9+
updateReviewStatus: async (
10+
_parent: undefined,
11+
{ applicantRecordId, reviewerId, status }: { applicantRecordId: string; reviewerId: number; status: ReviewStatus },
12+
): Promise<ReviewedApplicantRecordDTO> => {
13+
return reviewedApplicantRecordService.updateReviewStatus(
14+
applicantRecordId,
15+
reviewerId,
16+
status,
17+
);
18+
},
19+
},
20+
};
21+
22+
export default reviewedApplicantRecordResolvers;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { gql } from "apollo-server-express";
2+
3+
const reviewedApplicantRecordType = gql`
4+
enum ReviewStatus {
5+
NeedsReview
6+
InProgress
7+
Done
8+
ConflictReported
9+
}
10+
11+
type Review {
12+
passionFSG: Int
13+
teamPlayer: Int
14+
desireToLearn: Int
15+
skill: Int
16+
skillCategory: String
17+
}
18+
19+
type ReviewedApplicantRecordDTO {
20+
applicantRecordId: String!
21+
reviewerId: Int!
22+
review: Review!
23+
status: ReviewStatus!
24+
score: Int
25+
reviewerHasConflict: Boolean!
26+
}
27+
28+
extend type Mutation {
29+
updateReviewStatus(
30+
applicantRecordId: String!
31+
reviewerId: Int!
32+
status: ReviewStatus!
33+
): ReviewedApplicantRecordDTO!
34+
}
35+
`;
36+
37+
export default reviewedApplicantRecordType;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { ReviewedApplicantRecordDTO, ReviewStatus } from "../../types";
2+
import { getErrorMessage } from "../../utilities/errorUtils";
3+
import logger from "../../utilities/logger";
4+
import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
5+
import IReviewedApplicantRecordService from "../interfaces/reviewedApplicantRecordService";
6+
7+
const Logger = logger(__filename);
8+
9+
class ReviewedApplicantRecordService implements IReviewedApplicantRecordService {
10+
/* eslint-disable class-methods-use-this */
11+
12+
async updateReviewStatus(
13+
applicantRecordId: string,
14+
reviewerId: number,
15+
status: ReviewStatus
16+
): Promise<ReviewedApplicantRecordDTO> {
17+
const applicantRecord = await ReviewedApplicantRecord.findOne({
18+
where: { applicantRecordId, reviewerId },
19+
});
20+
if (!applicantRecord) {
21+
throw new Error(
22+
`ReviewedApplicantRecord with applicantRecordId ${applicantRecordId} and reviewerId ${reviewerId} not found.`
23+
);
24+
}
25+
try {
26+
applicantRecord.status = status;
27+
await applicantRecord.save();
28+
return {
29+
applicantRecordId: applicantRecord.applicantRecordId,
30+
reviewerId: applicantRecord.reviewerId,
31+
review: applicantRecord.review,
32+
status: applicantRecord.status,
33+
score: applicantRecord.score,
34+
reviewerHasConflict: applicantRecord.reviewerHasConflict,
35+
};
36+
} catch (error: unknown) {
37+
Logger.error(
38+
`Failed to update review status. Reason = ${getErrorMessage(error)}`,
39+
);
40+
throw error;
41+
}
42+
}
43+
}
44+
45+
export default ReviewedApplicantRecordService;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ReviewedApplicantRecordDTO, ReviewStatus } from "../../types";
2+
3+
interface IReviewedApplicantRecordService {
4+
updateReviewStatus(
5+
applicantRecordId: string,
6+
reviewerId: number,
7+
status: ReviewStatus
8+
): Promise<ReviewedApplicantRecordDTO>;
9+
}
10+
11+
export default IReviewedApplicantRecordService;

backend/typescript/types.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,11 @@ export type ProductPositionTitle = (typeof ProductPositionTitles)[number];
182182
export type CommunityPositionTitle = (typeof CommunityPositionTitles)[number];
183183
export type PositionTitle = (typeof PositionTitles)[number];
184184

185-
export enum ReviewStatusEnum {
186-
TODO = "Todo",
187-
IN_PROGRESS = "In Progress",
188-
DONE = "Done",
189-
CONFLICT = "Conflict",
190-
}
191-
192-
export type ReviewStatus = `${ReviewStatusEnum}`;
185+
export type ReviewStatus =
186+
| "NeedsReview"
187+
| "InProgress"
188+
| "Done"
189+
| "ConflictReported";
193190

194191
export type Review = {
195192
passionFSG?: number;

0 commit comments

Comments
 (0)