Skip to content

Commit 0a494f5

Browse files
Merge pull request #80 from uwblueprint/INTF25-queries-for-admin-comments
[INTF25] Adds queries for admin comments
2 parents 5345a50 + 007e738 commit 0a494f5

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

backend/typescript/graphql/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const graphQLMiddlewares = {
7171
userByEmail: authorizedByAdmin(),
7272
login: authorizedByAdmin(),
7373
users: authorizedByAdmin(),
74+
adminCommentsByApplicantRecordId: authorizedByAdmin(),
75+
adminCommentById: authorizedByAdmin(),
7476
},
7577
Mutation: {
7678
createEntity: authorizedByAllRoles(),

backend/typescript/graphql/resolvers/adminCommentsResolvers.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ 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 =
14+
await adminCommentService.getAdminCommentsByApplicantRecordId(
15+
applicantRecordId,
16+
);
17+
return adminComments;
18+
},
19+
adminCommentById: async (
20+
_parent: undefined,
21+
{ id }: { id: string },
22+
): Promise<AdminCommentDTO> => {
23+
const adminComment = await adminCommentService.getAdminCommentById(id);
24+
return adminComment;
25+
},
26+
},
827
Mutation: {
928
createAdminComment: async (
1029
_parent: undefined,

backend/typescript/graphql/types/adminCommentsType.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const adminCommentsType = gql`
1616
comment: String!
1717
}
1818
19+
extend type Query {
20+
adminCommentsByApplicantRecordId(
21+
applicantRecordId: String!
22+
): [AdminCommentDTO!]!
23+
adminCommentById(id: String!): AdminCommentDTO!
24+
}
25+
1926
extend type Mutation {
2027
createAdminComment(adminComment: CreateAdminCommentDTO!): AdminCommentDTO!
2128
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+
applicantRecordId: string,
29+
): Promise<AdminCommentDTO[]> {
30+
let adminComments: AdminComment[] = [];
31+
let adminCommentDTOs: Array<AdminCommentDTO> = [];
32+
try {
33+
adminComments = await AdminComment.findAll({
34+
where: { applicantRecordId },
35+
});
36+
adminCommentDTOs = adminComments.map((adminComment) => ({
37+
id: adminComment.id,
38+
userId: adminComment.userId,
39+
applicantRecordId: adminComment.applicantRecordId,
40+
comment: adminComment.comment,
41+
createdAt: adminComment.createdAt.toISOString(),
42+
updatedAt: adminComment.updatedAt.toISOString(),
43+
}));
44+
} catch (error: unknown) {
45+
Logger.error(
46+
`Failed to get admin comments by reviewedApplicantRecordId = ${applicantRecordId}. Reason = ${getErrorMessage(
47+
error,
48+
)}`,
49+
);
50+
throw error;
51+
}
52+
return adminCommentDTOs;
53+
}
54+
55+
async getAdminCommentById(id: string): Promise<AdminCommentDTO> {
56+
try {
57+
const adminComment = await grabAdminComment(id);
58+
return {
59+
id: String(adminComment.id),
60+
userId: adminComment.userId,
61+
applicantRecordId: String(adminComment.applicantRecordId),
62+
comment: adminComment.comment,
63+
createdAt: adminComment.createdAt.toISOString(),
64+
updatedAt: adminComment.updatedAt.toISOString(),
65+
};
66+
} catch (error: unknown) {
67+
Logger.error(
68+
`Failed to get admin comment by id = ${id}. Reason = ${getErrorMessage(
69+
error,
70+
)}`,
71+
);
72+
throw error;
73+
}
74+
}
75+
2776
async createAdminComment(
2877
content: CreateAdminCommentDTO,
2978
): Promise<AdminCommentDTO> {

backend/typescript/services/interfaces/adminCommentService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { AdminCommentDTO, CreateAdminCommentDTO } from "../../types";
22

33
interface IAdminCommentService {
4+
getAdminCommentsByApplicantRecordId(
5+
reviewedApplicantRecordId: string,
6+
): Promise<AdminCommentDTO[]>;
7+
getAdminCommentById(id: string): Promise<AdminCommentDTO>;
48
createAdminComment(content: CreateAdminCommentDTO): Promise<AdminCommentDTO>;
59
updateAdminComment(
610
commentId: string,

0 commit comments

Comments
 (0)