Skip to content

Commit 1f954df

Browse files
author
Maggie Chen
committed
ran lint and wrapped service function in try catch
1 parent b341617 commit 1f954df

File tree

6 files changed

+139
-83
lines changed

6 files changed

+139
-83
lines changed

backend/typescript/graphql/resolvers/reviewedApplicantRecordResolver.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import ReviewedApplicantRecordService from "../../services/implementations/reviewedApplicantRecordService";
2-
import {
3-
ReviewedApplicantRecordDTO,
2+
import {
3+
ReviewedApplicantRecordDTO,
44
CreateReviewedApplicantRecordDTO,
5-
DeleteReviewedApplicantRecordDTO
5+
DeleteReviewedApplicantRecordDTO,
66
} from "../../types";
77
import { getErrorMessage } from "../../utilities/errorUtils";
88

@@ -15,7 +15,9 @@ const reviewedApplicantRecordResolvers = {
1515
args: { input: CreateReviewedApplicantRecordDTO },
1616
): Promise<ReviewedApplicantRecordDTO> => {
1717
try {
18-
return await reviewedApplicantRecordService.createReviewedApplicantRecord(args.input);
18+
return await reviewedApplicantRecordService.createReviewedApplicantRecord(
19+
args.input,
20+
);
1921
} catch (error) {
2022
throw new Error(getErrorMessage(error));
2123
}
@@ -26,7 +28,9 @@ const reviewedApplicantRecordResolvers = {
2628
args: { inputs: CreateReviewedApplicantRecordDTO[] },
2729
): Promise<ReviewedApplicantRecordDTO[]> => {
2830
try {
29-
return await reviewedApplicantRecordService.bulkCreateReviewedApplicantRecord(args.inputs);
31+
return await reviewedApplicantRecordService.bulkCreateReviewedApplicantRecord(
32+
args.inputs,
33+
);
3034
} catch (error) {
3135
throw new Error(getErrorMessage(error));
3236
}
@@ -38,7 +42,7 @@ const reviewedApplicantRecordResolvers = {
3842
): Promise<ReviewedApplicantRecordDTO> => {
3943
try {
4044
return await reviewedApplicantRecordService.deleteReviewedApplicantRecord(
41-
args.input
45+
args.input,
4246
);
4347
} catch (error) {
4448
throw new Error(getErrorMessage(error));
@@ -51,7 +55,7 @@ const reviewedApplicantRecordResolvers = {
5155
): Promise<ReviewedApplicantRecordDTO[]> => {
5256
try {
5357
return await reviewedApplicantRecordService.bulkDeleteReviewedApplicantRecord(
54-
args.inputs
58+
args.inputs,
5559
);
5660
} catch (error) {
5761
throw new Error(getErrorMessage(error));

backend/typescript/graphql/types/reviewedApplicantRecordTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ const reviewedApplicantRecordTypes = gql`
6262
): [ReviewedApplicantRecord!]!
6363
}
6464
`;
65-
65+
6666
export default reviewedApplicantRecordTypes;

backend/typescript/migrations/20251112023004-add-createdat-updatedat-to-reviewed-application.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { Migration } from "../umzug";
44
const TABLE_NAME = "reviewed_applicant_records";
55

66
export const up: Migration = async ({ context: sequelize }) => {
7-
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "createdAt", {
8-
type: DataType.DATE,
9-
allowNull: false,
10-
defaultValue: DataType.NOW
11-
})
7+
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "createdAt", {
8+
type: DataType.DATE,
9+
allowNull: false,
10+
defaultValue: DataType.NOW,
11+
});
1212

13-
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "updatedAt", {
14-
type: DataType.DATE,
15-
allowNull: false,
16-
defaultValue: DataType.NOW
17-
})
13+
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "updatedAt", {
14+
type: DataType.DATE,
15+
allowNull: false,
16+
defaultValue: DataType.NOW,
17+
});
1818
};
1919

2020
export const down: Migration = async ({ context: sequelize }) => {
21-
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "createdAt");
22-
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "updatedAt");
21+
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "createdAt");
22+
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "updatedAt");
2323
};
Lines changed: 104 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,126 @@
11
import { sequelize } from "../../models";
22
import ReviewedApplicantRecord from "../../models/reviewedApplicantRecord.model";
3-
import {
4-
ReviewedApplicantRecordDTO,
5-
CreateReviewedApplicantRecordDTO,
6-
DeleteReviewedApplicantRecordDTO
3+
import {
4+
ReviewedApplicantRecordDTO,
5+
CreateReviewedApplicantRecordDTO,
6+
DeleteReviewedApplicantRecordDTO,
77
} from "../../types";
8-
8+
import { getErrorMessage } from "../../utilities/errorUtils";
9+
import logger from "../../utilities/logger";
910
import IReviewApplicantRecordService from "../interfaces/IReviewedApplicantRecordService";
1011

11-
class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
12+
const Logger = logger(__filename);
1213

13-
async createReviewedApplicantRecord(
14-
dto: CreateReviewedApplicantRecordDTO
15-
): Promise<ReviewedApplicantRecordDTO> {
16-
const record = await ReviewedApplicantRecord.create(dto);
17-
return record.toJSON() as ReviewedApplicantRecordDTO;
14+
class ReviewedApplicantRecordService implements IReviewApplicantRecordService {
15+
/* eslint-disable class-methods-use-this */
16+
async createReviewedApplicantRecord(
17+
dto: CreateReviewedApplicantRecordDTO,
18+
): Promise<ReviewedApplicantRecordDTO> {
19+
try {
20+
const record = await ReviewedApplicantRecord.create(dto);
21+
return record.toJSON() as ReviewedApplicantRecordDTO;
22+
} catch (error: unknown) {
23+
Logger.error(
24+
`Failed to create reviewed applicant record. Reason = ${getErrorMessage(
25+
error,
26+
)}`,
27+
);
28+
throw error;
1829
}
30+
}
1931

20-
async bulkCreateReviewedApplicantRecord(
21-
createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[]
22-
): Promise<ReviewedApplicantRecordDTO[]> {
23-
const reviewedApplicantRecords = await sequelize.transaction(async (t) => {
24-
const records = await ReviewedApplicantRecord.bulkCreate(
25-
createReviewedApplicantRecordDTOs,
26-
{ transaction: t }
27-
);
28-
return records;
29-
});
32+
async bulkCreateReviewedApplicantRecord(
33+
createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[],
34+
): Promise<ReviewedApplicantRecordDTO[]> {
35+
try {
36+
const reviewedApplicantRecords = await sequelize.transaction(
37+
async (t) => {
38+
const records = await ReviewedApplicantRecord.bulkCreate(
39+
createReviewedApplicantRecordDTOs,
40+
{ transaction: t },
41+
);
42+
return records;
43+
},
44+
);
3045

31-
return reviewedApplicantRecords.map((record) =>
32-
record.toJSON() as ReviewedApplicantRecordDTO
33-
);
46+
return reviewedApplicantRecords.map(
47+
(record) => record.toJSON() as ReviewedApplicantRecordDTO,
48+
);
49+
} catch (error: unknown) {
50+
Logger.error(
51+
`Failed to bulk create reviewed applicant records. Reason = ${getErrorMessage(
52+
error,
53+
)}`,
54+
);
55+
throw error;
3456
}
57+
}
3558

36-
async deleteReviewedApplicantRecord(deleteReviewedApplicantRecord: DeleteReviewedApplicantRecordDTO): Promise<ReviewedApplicantRecordDTO> {
37-
const applicantRecordId = deleteReviewedApplicantRecord.applicantRecordId;
38-
const reviewerId = deleteReviewedApplicantRecord.reviewerId;
39-
const record = await ReviewedApplicantRecord.findOne({ where: { applicantRecordId, reviewerId } });
59+
async deleteReviewedApplicantRecord(
60+
deleteReviewedApplicantRecord: DeleteReviewedApplicantRecordDTO,
61+
): Promise<ReviewedApplicantRecordDTO> {
62+
try {
63+
const { applicantRecordId } = deleteReviewedApplicantRecord;
64+
const { reviewerId } = deleteReviewedApplicantRecord;
65+
const record = await ReviewedApplicantRecord.findOne({
66+
where: { applicantRecordId, reviewerId },
67+
});
4068

41-
if (!record) {
42-
throw new Error("ReviewedApplicantRecord not found, delete failed");
43-
}
69+
if (!record) {
70+
throw new Error("ReviewedApplicantRecord not found, delete failed");
71+
}
4472

45-
await record.destroy();
46-
return record.toJSON() as ReviewedApplicantRecordDTO;
73+
await record.destroy();
74+
return record.toJSON() as ReviewedApplicantRecordDTO;
75+
} catch (error: unknown) {
76+
Logger.error(
77+
`Failed to bulk create reviewed applicant records. Reason = ${getErrorMessage(
78+
error,
79+
)}`,
80+
);
81+
throw error;
4782
}
83+
}
4884

49-
async bulkDeleteReviewedApplicantRecord(deleteReviewedApplicantRecords: DeleteReviewedApplicantRecordDTO[]): Promise<ReviewedApplicantRecordDTO[]> {
50-
const deletedRecords = await sequelize.transaction(async (t) => {
51-
const records = await Promise.all(
52-
deleteReviewedApplicantRecords.map(({ applicantRecordId, reviewerId }) =>
53-
ReviewedApplicantRecord.findOne({
54-
where: { applicantRecordId, reviewerId },
55-
transaction: t,
56-
})
57-
)
58-
);
85+
async bulkDeleteReviewedApplicantRecord(
86+
deleteReviewedApplicantRecords: DeleteReviewedApplicantRecordDTO[],
87+
): Promise<ReviewedApplicantRecordDTO[]> {
88+
try {
89+
const deletedRecords = await sequelize.transaction(async (t) => {
90+
const records = await Promise.all(
91+
deleteReviewedApplicantRecords.map(
92+
({ applicantRecordId, reviewerId }) =>
93+
ReviewedApplicantRecord.findOne({
94+
where: { applicantRecordId, reviewerId },
95+
transaction: t,
96+
}),
97+
),
98+
);
5999

60-
if (records.some((r) => !r)) {
61-
throw new Error("Not all records were found, bulk delete failed");
62-
}
100+
if (records.some((r) => !r)) {
101+
throw new Error("Not all records were found, bulk delete failed");
102+
}
63103

64-
const existingRecords = records as ReviewedApplicantRecord[];
65-
await Promise.all(existingRecords.map((r) => r.destroy({ transaction: t })));
104+
const existingRecords = records as ReviewedApplicantRecord[];
105+
await Promise.all(
106+
existingRecords.map((r) => r.destroy({ transaction: t })),
107+
);
66108

67-
return existingRecords;
68-
});
109+
return existingRecords;
110+
});
69111

70-
return deletedRecords.map((r) => r.toJSON() as ReviewedApplicantRecordDTO);
112+
return deletedRecords.map(
113+
(r) => r.toJSON() as ReviewedApplicantRecordDTO,
114+
);
115+
} catch (error: unknown) {
116+
Logger.error(
117+
`Failed to bulk create reviewed applicant records. Reason = ${getErrorMessage(
118+
error,
119+
)}`,
120+
);
121+
throw error;
71122
}
123+
}
72124
}
73125

74-
export default ReviewedApplicantRecordService;
126+
export default ReviewedApplicantRecordService;
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import {
2-
ReviewedApplicantRecordDTO,
3-
CreateReviewedApplicantRecordDTO,
4-
DeleteReviewedApplicantRecordDTO
1+
import {
2+
ReviewedApplicantRecordDTO,
3+
CreateReviewedApplicantRecordDTO,
4+
DeleteReviewedApplicantRecordDTO,
55
} from "../../types";
66

77
interface IReviewApplicantRecordService {
@@ -10,15 +10,15 @@ interface IReviewApplicantRecordService {
1010
* @Param createReviewedApplicantRecordDTO data to create reviewed applicant record
1111
*/
1212
createReviewedApplicantRecord(
13-
createReviewedApplicantRecordDTO: CreateReviewedApplicantRecordDTO
13+
createReviewedApplicantRecordDTO: CreateReviewedApplicantRecordDTO,
1414
): Promise<ReviewedApplicantRecordDTO>;
1515

1616
/**
1717
* Creates multiple reviewed applicant record entries in bulk
1818
* @Param createReviewedApplicantRecordDTOs array of data to create reviewed applicant records
1919
*/
2020
bulkCreateReviewedApplicantRecord(
21-
createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[]
21+
createReviewedApplicantRecordDTOs: CreateReviewedApplicantRecordDTO[],
2222
): Promise<ReviewedApplicantRecordDTO[]>;
2323

2424
/**
@@ -27,16 +27,16 @@ interface IReviewApplicantRecordService {
2727
* @Param reviewerId the ID of the reviewer
2828
*/
2929
deleteReviewedApplicantRecord(
30-
deleteReviewedApplicantRecord: DeleteReviewedApplicantRecordDTO
30+
deleteReviewedApplicantRecord: DeleteReviewedApplicantRecordDTO,
3131
): Promise<ReviewedApplicantRecordDTO>;
3232

3333
/**
3434
* Deletes multiple reviewed applicant record entries in bulk
3535
* @Param deleteReviewedApplicantRecord array of data to delete reviewed applicant records
3636
*/
3737
bulkDeleteReviewedApplicantRecord(
38-
deleteReviewedApplicantRecords: DeleteReviewedApplicantRecordDTO[]
38+
deleteReviewedApplicantRecords: DeleteReviewedApplicantRecordDTO[],
3939
): Promise<ReviewedApplicantRecordDTO[]>;
4040
}
4141

42-
export default IReviewApplicantRecordService;
42+
export default IReviewApplicantRecordService;

backend/typescript/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ export type CreateReviewedApplicantRecordDTO = {
213213
reviewerId: number;
214214
review?: Review;
215215
reviewerHasConflict?: boolean;
216-
}
216+
};
217217

218218
export type DeleteReviewedApplicantRecordDTO = {
219219
applicantRecordId: string;
220220
reviewerId: number;
221-
}
221+
};
222222

223223
export type AdminCommentDTO = {
224224
id: string;

0 commit comments

Comments
 (0)