Skip to content

Commit a060abe

Browse files
cleanup
1 parent ff42da4 commit a060abe

File tree

5 files changed

+48
-29
lines changed

5 files changed

+48
-29
lines changed

backend/typescript/graphql/resolvers/reviewedApplicantRecordResolver.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import ReviewedApplicantRecordService from "../../services/implementations/reviewedApplicantRecordService";
2-
import { ReviewedApplicantRecordDTO, CreateReviewedApplicantRecordDTO } from "../../types";
2+
import {
3+
ReviewedApplicantRecordDTO,
4+
CreateReviewedApplicantRecordDTO,
5+
DeleteReviewedApplicantRecord
6+
} from "../../types";
37
import { getErrorMessage } from "../../utilities/errorUtils";
48

59
const reviewedApplicantRecordService = new ReviewedApplicantRecordService();
@@ -30,12 +34,11 @@ const reviewedApplicantRecordResolvers = {
3034

3135
deleteReviewedApplicantRecord: async (
3236
_parent: undefined,
33-
args: { applicantRecordId: string; reviewerId: number },
37+
args: { input: DeleteReviewedApplicantRecord },
3438
): Promise<ReviewedApplicantRecordDTO> => {
3539
try {
3640
return await reviewedApplicantRecordService.deleteReviewedApplicantRecord(
37-
args.applicantRecordId,
38-
args.reviewerId,
41+
args.input
3942
);
4043
} catch (error) {
4144
throw new Error(getErrorMessage(error));
@@ -44,12 +47,11 @@ const reviewedApplicantRecordResolvers = {
4447

4548
bulkDeleteReviewedApplicantRecord: async (
4649
_parent: undefined,
47-
args: { applicantRecordIds: string[]; reviewerId: number },
50+
args: { inputs: DeleteReviewedApplicantRecord[] },
4851
): Promise<ReviewedApplicantRecordDTO[]> => {
4952
try {
5053
return await reviewedApplicantRecordService.bulkDeleteReviewedApplicantRecord(
51-
args.applicantRecordIds,
52-
args.reviewerId,
54+
args.inputs
5355
);
5456
} catch (error) {
5557
throw new Error(getErrorMessage(error));

backend/typescript/graphql/types/reviewedApplicantRecordTypes.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const reviewedApplicantRecordTypes = gql`
1717
status: String
1818
}
1919
20+
input DeleteReviewedApplicantRecord {
21+
applicantRecordId: ID!
22+
reviewerId: Int!
23+
}
24+
2025
extend type Mutation {
2126
createReviewedApplicantRecord(
2227
input: CreateReviewedApplicantRecordInput!
@@ -27,13 +32,11 @@ const reviewedApplicantRecordTypes = gql`
2732
): [ReviewedApplicantRecord!]!
2833
2934
deleteReviewedApplicantRecord(
30-
applicantRecordId: ID!
31-
reviewerId: Int!
35+
input: DeleteReviewedApplicantRecord!
3236
): ReviewedApplicantRecord!
3337
3438
bulkDeleteReviewedApplicantRecord(
35-
applicantRecordIds: [ID!]!
36-
reviewerId: Int!
39+
inputs: [DeleteReviewedApplicantRecord!]!
3740
): [ReviewedApplicantRecord!]!
3841
}
3942
`;

backend/typescript/services/implementations/reviewedApplicantRecordService.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { sequelize } from "../../models";
22
import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
33
import {
44
ReviewedApplicantRecordDTO,
5-
CreateReviewedApplicantRecordDTO
5+
CreateReviewedApplicantRecordDTO,
6+
DeleteReviewedApplicantRecord
67
} from "../../types";
78

8-
import IReviewApplicantRecordService from "../interfaces/reviewedApplicantRecordService";
9+
import IReviewApplicantRecordService from "../interfaces/IReviewedApplicantRecordService";
910

1011
class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
1112

@@ -33,7 +34,9 @@ class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
3334
}
3435

3536
// Methods deleteReviewedApplicantRecord and bulkDeleteReviewedApplicantRecord would be implemented here
36-
async deleteReviewedApplicantRecord(applicantRecordId: string, reviewerId: number): Promise<ReviewedApplicantRecordDTO> {
37+
async deleteReviewedApplicantRecord(deleteReviewedApplicantRecord: DeleteReviewedApplicantRecord): Promise<ReviewedApplicantRecordDTO> {
38+
const applicantRecordId = deleteReviewedApplicantRecord.applicantRecordId;
39+
const reviewerId = deleteReviewedApplicantRecord.reviewerId;
3740
const record = await ReviewedApplicantRecord.findOne({ where: { applicantRecordId, reviewerId } });
3841

3942
if (!record) {
@@ -44,17 +47,25 @@ class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
4447
return record.toJSON() as ReviewedApplicantRecordDTO;
4548
}
4649

47-
async bulkDeleteReviewedApplicantRecord(applicantRecordIds: string[], reviewerId: number): Promise<ReviewedApplicantRecordDTO[]> {
50+
async bulkDeleteReviewedApplicantRecord(deleteReviewedApplicantRecords: DeleteReviewedApplicantRecord[]): Promise<ReviewedApplicantRecordDTO[]> {
4851
const deletedRecords = await sequelize.transaction(async (t) => {
49-
const records = await ReviewedApplicantRecord.findAll({
50-
where: { applicantRecordId: applicantRecordIds, reviewerId },
51-
transaction: t,
52-
});
52+
const records = await Promise.all(
53+
deleteReviewedApplicantRecords.map(({ applicantRecordId, reviewerId }) =>
54+
ReviewedApplicantRecord.findOne({
55+
where: { applicantRecordId, reviewerId },
56+
transaction: t,
57+
})
58+
)
59+
);
5360

54-
if (records.length === 0) return [];
61+
if (records.some((r) => !r)) {
62+
throw new Error("Not all records were found, bulk delete aborted.");
63+
}
5564

56-
await Promise.all(records.map((r) => r.destroy({ transaction: t })));
57-
return records;
65+
const existingRecords = records as ReviewedApplicantRecord[];
66+
await Promise.all(existingRecords.map((r) => r.destroy({ transaction: t })));
67+
68+
return existingRecords;
5869
});
5970

6071
return deletedRecords.map((r) => r.toJSON() as ReviewedApplicantRecordDTO);

backend/typescript/services/interfaces/reviewedApplicantRecordService.ts renamed to backend/typescript/services/interfaces/IReviewedApplicantRecordService.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ReviewedApplicantRecordDTO,
3-
CreateReviewedApplicantRecordDTO
3+
CreateReviewedApplicantRecordDTO,
4+
DeleteReviewedApplicantRecord
45
} from "../../types";
56

67
interface IReviewApplicantRecordService {
@@ -26,18 +27,15 @@ interface IReviewApplicantRecordService {
2627
* @Param reviewerId the ID of the reviewer
2728
*/
2829
deleteReviewedApplicantRecord(
29-
applicantRecordId: string,
30-
reviewerId: number
30+
deleteReviewedApplicantRecord: DeleteReviewedApplicantRecord
3131
): Promise<ReviewedApplicantRecordDTO>;
3232

3333
/**
3434
* 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
35+
* @Param deleteReviewedApplicantRecord array of data to delete reviewed applicant records
3736
*/
3837
bulkDeleteReviewedApplicantRecord(
39-
applicantRecordIds: string[],
40-
reviewerId: number
38+
deleteReviewedApplicantRecords: DeleteReviewedApplicantRecord[]
4139
): Promise<ReviewedApplicantRecordDTO[]>;
4240
}
4341

backend/typescript/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,8 @@ export type CreateReviewedApplicantRecordDTO = {
262262
review?: Review;
263263
reviewerHasConflict?: boolean;
264264
}
265+
266+
export type DeleteReviewedApplicantRecord = {
267+
applicantRecordId: string;
268+
reviewerId: number;
269+
}

0 commit comments

Comments
 (0)