Skip to content

Commit 8ddbc7f

Browse files
committed
add queries for fetching admin comments by applicantRecordId and id
1 parent a4248e8 commit 8ddbc7f

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

backend/typescript/graphql/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const graphQLMiddlewares = {
7575
userByEmail: authorizedByAdmin(),
7676
login: authorizedByAdmin(),
7777
users: authorizedByAdmin(),
78+
adminCommentsByApplicantRecordId: authorizedByAdmin(),
79+
adminCommentById: authorizedByAdmin(),
7880
},
7981
Mutation: {
8082
createEntity: authorizedByAllRoles(),

backend/typescript/graphql/resolvers/adminCommentsResolvers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ import { CreateAdminCommentDTO, AdminCommentDTO } from "../../types";
55
const adminCommentService: IAdminCommentService = new AdminCommentService();
66

77
const adminCommentResolvers = {
8+
Query: {
9+
adminCommentsByApplicantRecordId: async (
10+
_parent: undefined,
11+
{ applicantRecordId }: { applicantRecordId: string },
12+
): Promise<AdminCommentDTO[]> => {
13+
const adminComments = await adminCommentService.getAdminCommentsByApplicantRecordId(applicantRecordId);
14+
return adminComments;
15+
},
16+
adminCommentById: async (
17+
_parent: undefined,
18+
{ id }: { id: string },
19+
): Promise<AdminCommentDTO> => {
20+
const adminComment = await adminCommentService.getAdminCommentById(id);
21+
return adminComment;
22+
},
23+
},
824
Mutation: {
925
createAdminComment: async (
1026
_parent: undefined,

backend/typescript/graphql/types/adminCommentsType.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const adminCommentsType = gql`
1616
comment: String!
1717
}
1818
19+
extend type Query {
20+
adminCommentsByApplicantRecordId(applicantRecordId: String!): [AdminCommentDTO!]!
21+
adminCommentById(id: String!): AdminCommentDTO!
22+
}
23+
1924
extend type Mutation {
2025
createAdminComment(adminComment: CreateAdminCommentDTO!): AdminCommentDTO!
2126
updateAdminComment(

backend/typescript/services/implementations/adminCommentService.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,55 @@ const grabAdminComment = async (commentId: string): Promise<AdminComment> => {
2424
class AdminCommentService implements IAdminCommentService {
2525
/* eslint-disable class-methods-use-this */
2626

27+
async getAdminCommentsByApplicantRecordId(
28+
reviewedApplicantRecordId: string,
29+
): Promise<AdminCommentDTO[]> {
30+
let adminComments: AdminComment[] = [];
31+
let adminCommentDTOs: Array<AdminCommentDTO> = [];
32+
try {
33+
adminComments = await AdminComment.findAll({
34+
where: { reviewedApplicantRecordId },
35+
});
36+
adminCommentDTOs = await adminComments.map((adminComment) => {
37+
return {
38+
id: adminComment.id;
39+
userId: adminComment.userId;
40+
applicantRecordId: adminComment.applicantRecordId;
41+
comment: adminComment.comment;
42+
createdAt: adminComment.createdAt;
43+
updatedAt: adminComment.updatedAt;
44+
};
45+
});
46+
} catch (error: unknown) {
47+
Logger.error(
48+
`Failed to get admin comments by reviewedApplicantRecordId = ${reviewedApplicantRecordId}. Reason = ${getErrorMessage(
49+
error,
50+
)}`,
51+
);
52+
throw error;
53+
}
54+
return adminCommentDTOs;
55+
}
56+
57+
async getAdminCommentById(id: string): Promise<AdminCommentDTO> {
58+
try {
59+
const adminComment = await grabAdminComment(id);
60+
return {
61+
id: String(adminComment.id),
62+
userId: adminComment.userId,
63+
applicantRecordId: String(adminComment.applicantRecordId),
64+
comment: adminComment.comment,
65+
createdAt: adminComment.createdAt.toISOString(),
66+
updatedAt: adminComment.updatedAt.toISOString(),
67+
};
68+
} catch (error: unknown) {
69+
Logger.error(
70+
`Failed to get admin comment by id = ${id}. Reason = ${getErrorMessage(error)}`,
71+
);
72+
throw error;
73+
}
74+
}
75+
2776
async createAdminComment(
2877
content: CreateAdminCommentDTO,
2978
): Promise<AdminCommentDTO> {

0 commit comments

Comments
 (0)