Skip to content

Commit b8b9a8f

Browse files
isabelle huangisabelle huang
authored andcommitted
current draft
1 parent 517ed7d commit b8b9a8f

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import ReviewedApplicantRecordService from "../../services/implementations/reviewedApplicantRecordService";
2+
import { ReviewedApplicantRecordDTO, CreateReviewedApplicantRecordDTO } from "../../types";
3+
import { getErrorMessage } from "../../utilities/errorUtils";
4+
5+
const reviewedApplicantRecordService = new ReviewedApplicantRecordService();
6+
7+
const reviewedApplicantRecordResolvers = {
8+
Mutation: {
9+
createReviewedApplicantRecord: async (
10+
_parent: undefined,
11+
args: { input: CreateReviewedApplicantRecordDTO },
12+
): Promise<ReviewedApplicantRecordDTO> => {
13+
try {
14+
return await reviewedApplicantRecordService.createReviewedApplicantRecord(args.input);
15+
} catch (error) {
16+
throw new Error(getErrorMessage(error));
17+
}
18+
},
19+
20+
bulkCreateReviewedApplicantRecord: async (
21+
_parent: undefined,
22+
args: { inputs: CreateReviewedApplicantRecordDTO[] },
23+
): Promise<ReviewedApplicantRecordDTO[]> => {
24+
try {
25+
return await reviewedApplicantRecordService.bulkCreateReviewedApplicantRecord(args.inputs);
26+
} catch (error) {
27+
throw new Error(getErrorMessage(error));
28+
}
29+
},
30+
31+
deleteReviewedApplicantRecord: async (
32+
_parent: undefined,
33+
args: { applicantRecordId: string; reviewerId: number },
34+
): Promise<ReviewedApplicantRecordDTO> => {
35+
try {
36+
return await reviewedApplicantRecordService.deleteReviewedApplicantRecord(
37+
args.applicantRecordId,
38+
args.reviewerId,
39+
);
40+
} catch (error) {
41+
throw new Error(getErrorMessage(error));
42+
}
43+
},
44+
45+
bulkDeleteReviewedApplicantRecord: async (
46+
_parent: undefined,
47+
args: { applicantRecordIds: string[]; reviewerId: number },
48+
): Promise<ReviewedApplicantRecordDTO[]> => {
49+
try {
50+
return await reviewedApplicantRecordService.bulkDeleteReviewedApplicantRecord(
51+
args.applicantRecordIds,
52+
args.reviewerId,
53+
);
54+
} catch (error) {
55+
throw new Error(getErrorMessage(error));
56+
}
57+
},
58+
},
59+
};
60+
61+
export default reviewedApplicantRecordResolvers;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { gql } from "apollo-server-express";
2+
3+
const reviewedApplicantRecordTypes = gql`
4+
type ReviewedApplicantRecord {
5+
applicantRecordId: ID!
6+
reviewerId: Int!
7+
review: JSON
8+
status: String
9+
score: Int
10+
reviewerHasConflict: Boolean
11+
}
12+
13+
input CreateReviewedApplicantRecordInput {
14+
applicantRecordId: ID!
15+
reviewerId: Int!
16+
review: JSON
17+
status: String
18+
}
19+
20+
type Mutation {
21+
createReviewedApplicantRecord(
22+
input: CreateReviewedApplicantRecordInput!
23+
): ReviewedApplicantRecord!
24+
25+
bulkCreateReviewedApplicantRecord(
26+
inputs: [CreateReviewedApplicantRecordInput!]!
27+
): [ReviewedApplicantRecord!]!
28+
29+
deleteReviewedApplicantRecord(
30+
applicantRecordId: ID!
31+
reviewerId: Int!
32+
): ReviewedApplicantRecord!
33+
34+
bulkDeleteReviewedApplicantRecord(
35+
applicantRecordIds: [ID!]!
36+
reviewerId: Int!
37+
): [ReviewedApplicantRecord!]!
38+
}
39+
`;
40+
41+
export default reviewedApplicantRecordTypes;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { sequelize } from "../../models";
2+
import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
3+
import {
4+
ReviewedApplicantRecordDTO,
5+
CreateReviewedApplicantRecordDTO
6+
} from "../../types";
7+
8+
import IReviewApplicantRecordService from "../interfaces/reviewedApplicantRecordService";
9+
10+
class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
11+
12+
async createReviewedApplicantRecord(
13+
dto: CreateReviewedApplicantRecordDTO
14+
): Promise<ReviewedApplicantRecordDTO> {
15+
const record = await ReviewedApplicantRecord.create(dto);
16+
return record.toJSON() as ReviewedApplicantRecordDTO;
17+
}
18+
19+
async bulkCreateReviewedApplicantRecord(
20+
createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[]
21+
): Promise<ReviewedApplicantRecordDTO[]> {
22+
const reviewedApplicantRecords = await sequelize.transaction(async (t) => {
23+
const records = await ReviewedApplicantRecord.bulkCreate(
24+
createReviewedApplicantRecordDTOs,
25+
{ transaction: t }
26+
);
27+
return records;
28+
});
29+
30+
return reviewedApplicantRecords.map((record) =>
31+
record.toJSON() as ReviewedApplicantRecordDTO
32+
);
33+
}
34+
35+
// Methods deleteReviewedApplicantRecord and bulkDeleteReviewedApplicantRecord would be implemented here
36+
async deleteReviewedApplicantRecord(applicantRecordId: string, reviewerId: number): Promise<ReviewedApplicantRecordDTO> {
37+
const record = await ReviewedApplicantRecord.findOne({ where: { applicantRecordId, reviewerId } });
38+
39+
if (!record) {
40+
throw new Error("ReviewedApplicantRecord not found");
41+
}
42+
43+
await record.destroy();
44+
return record.toJSON() as ReviewedApplicantRecordDTO;
45+
}
46+
47+
async bulkDeleteReviewedApplicantRecord(applicantRecordIds: string[], reviewerId: number): Promise<ReviewedApplicantRecordDTO[]> {
48+
const deletedRecords = await sequelize.transaction(async (t) => {
49+
const records = await ReviewedApplicantRecord.findAll({
50+
where: { applicantRecordId: applicantRecordIds, reviewerId },
51+
transaction: t,
52+
});
53+
54+
if (records.length === 0) return [];
55+
56+
await Promise.all(records.map((r) => r.destroy({ transaction: t })));
57+
return records;
58+
});
59+
60+
return deletedRecords.map((r) => r.toJSON() as ReviewedApplicantRecordDTO);
61+
}
62+
}
63+
64+
export default ReviewedApplicantRecordService;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
ReviewedApplicantRecordDTO,
3+
CreateReviewedApplicantRecordDTO
4+
} from "../../types";
5+
6+
interface IReviewApplicantRecordService {
7+
/**
8+
* Creates a single reviewed applicant record entry
9+
* @Param createReviewedApplicantRecordDTO data to create reviewed applicant record
10+
*/
11+
createReviewedApplicantRecord(
12+
createReviewedApplicantRecordDTO: CreateReviewedApplicantRecordDTO
13+
): Promise<ReviewedApplicantRecordDTO>;
14+
15+
/**
16+
* Creates multiple reviewed applicant record entries in bulk
17+
* @Param createReviewedApplicantRecordDTOs array of data to create reviewed applicant records
18+
*/
19+
bulkCreateReviewedApplicantRecord(
20+
createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[]
21+
): Promise<ReviewedApplicantRecordDTO[]>;
22+
23+
/**
24+
* Deletes a single reviewed applicant record entry
25+
* @Param applicantRecordId the ID of applicant record to delete
26+
* @Param reviewerId the ID of the reviewer
27+
*/
28+
deleteReviewedApplicantRecord(
29+
applicantRecordId: string,
30+
reviewerId: number
31+
): Promise<ReviewedApplicantRecordDTO>;
32+
33+
/**
34+
* Deletes multiple reviewed applicant record entries in bulk
35+
* @Param applicantRecordIds array of applicant record IDs to delete
36+
* @Param reviewerId the ID of the reviewer
37+
*/
38+
bulkDeleteReviewedApplicantRecord(
39+
applicantRecordIds: string[],
40+
reviewerId: number
41+
): Promise<ReviewedApplicantRecordDTO[]>;
42+
}
43+
44+
export default IReviewApplicantRecordService;

backend/typescript/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,10 @@ export type ReviewedApplicantRecordDTO = {
255255
score?: number | null;
256256
reviewerHasConflict: boolean;
257257
};
258+
259+
export type CreateReviewedApplicantRecordDTO = {
260+
applicantRecordId: string;
261+
reviewerId: number;
262+
review?: Review;
263+
reviewerHasConflict?: boolean;
264+
}

0 commit comments

Comments
 (0)