diff --git a/backend/typescript/graphql/index.ts b/backend/typescript/graphql/index.ts index dd00ffa6..1197713d 100644 --- a/backend/typescript/graphql/index.ts +++ b/backend/typescript/graphql/index.ts @@ -75,6 +75,8 @@ const graphQLMiddlewares = { userByEmail: authorizedByAdmin(), login: authorizedByAdmin(), users: authorizedByAdmin(), + adminCommentsByApplicantRecordId: authorizedByAdmin(), + adminCommentById: authorizedByAdmin(), }, Mutation: { createEntity: authorizedByAllRoles(), diff --git a/backend/typescript/graphql/resolvers/adminCommentsResolvers.ts b/backend/typescript/graphql/resolvers/adminCommentsResolvers.ts index 58f07e28..5d8a4ca8 100644 --- a/backend/typescript/graphql/resolvers/adminCommentsResolvers.ts +++ b/backend/typescript/graphql/resolvers/adminCommentsResolvers.ts @@ -5,6 +5,25 @@ import { CreateAdminCommentDTO, AdminCommentDTO } from "../../types"; const adminCommentService: IAdminCommentService = new AdminCommentService(); const adminCommentResolvers = { + Query: { + adminCommentsByApplicantRecordId: async ( + _parent: undefined, + { applicantRecordId }: { applicantRecordId: string }, + ): Promise => { + const adminComments = + await adminCommentService.getAdminCommentsByApplicantRecordId( + applicantRecordId, + ); + return adminComments; + }, + adminCommentById: async ( + _parent: undefined, + { id }: { id: string }, + ): Promise => { + const adminComment = await adminCommentService.getAdminCommentById(id); + return adminComment; + }, + }, Mutation: { createAdminComment: async ( _parent: undefined, diff --git a/backend/typescript/graphql/types/adminCommentsType.ts b/backend/typescript/graphql/types/adminCommentsType.ts index d88ebbf6..489b55cf 100644 --- a/backend/typescript/graphql/types/adminCommentsType.ts +++ b/backend/typescript/graphql/types/adminCommentsType.ts @@ -16,6 +16,13 @@ const adminCommentsType = gql` comment: String! } + extend type Query { + adminCommentsByApplicantRecordId( + applicantRecordId: String! + ): [AdminCommentDTO!]! + adminCommentById(id: String!): AdminCommentDTO! + } + extend type Mutation { createAdminComment(adminComment: CreateAdminCommentDTO!): AdminCommentDTO! updateAdminComment( diff --git a/backend/typescript/services/implementations/adminCommentService.ts b/backend/typescript/services/implementations/adminCommentService.ts index 15c17e53..1224c250 100644 --- a/backend/typescript/services/implementations/adminCommentService.ts +++ b/backend/typescript/services/implementations/adminCommentService.ts @@ -24,6 +24,55 @@ const grabAdminComment = async (commentId: string): Promise => { class AdminCommentService implements IAdminCommentService { /* eslint-disable class-methods-use-this */ + async getAdminCommentsByApplicantRecordId( + applicantRecordId: string, + ): Promise { + let adminComments: AdminComment[] = []; + let adminCommentDTOs: Array = []; + try { + adminComments = await AdminComment.findAll({ + where: { applicantRecordId }, + }); + adminCommentDTOs = adminComments.map((adminComment) => ({ + id: adminComment.id, + userId: adminComment.userId, + applicantRecordId: adminComment.applicantRecordId, + comment: adminComment.comment, + createdAt: adminComment.createdAt.toISOString(), + updatedAt: adminComment.updatedAt.toISOString(), + })); + } catch (error: unknown) { + Logger.error( + `Failed to get admin comments by reviewedApplicantRecordId = ${applicantRecordId}. Reason = ${getErrorMessage( + error, + )}`, + ); + throw error; + } + return adminCommentDTOs; + } + + async getAdminCommentById(id: string): Promise { + try { + const adminComment = await grabAdminComment(id); + return { + id: String(adminComment.id), + userId: adminComment.userId, + applicantRecordId: String(adminComment.applicantRecordId), + comment: adminComment.comment, + createdAt: adminComment.createdAt.toISOString(), + updatedAt: adminComment.updatedAt.toISOString(), + }; + } catch (error: unknown) { + Logger.error( + `Failed to get admin comment by id = ${id}. Reason = ${getErrorMessage( + error, + )}`, + ); + throw error; + } + } + async createAdminComment( content: CreateAdminCommentDTO, ): Promise { diff --git a/backend/typescript/services/interfaces/adminCommentService.ts b/backend/typescript/services/interfaces/adminCommentService.ts index c676574a..a21c8da7 100644 --- a/backend/typescript/services/interfaces/adminCommentService.ts +++ b/backend/typescript/services/interfaces/adminCommentService.ts @@ -1,6 +1,10 @@ import { AdminCommentDTO, CreateAdminCommentDTO } from "../../types"; interface IAdminCommentService { + getAdminCommentsByApplicantRecordId( + reviewedApplicantRecordId: string, + ): Promise; + getAdminCommentById(id: string): Promise; createAdminComment(content: CreateAdminCommentDTO): Promise; updateAdminComment( commentId: string,