Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/typescript/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const graphQLMiddlewares = {
userByEmail: authorizedByAdmin(),
login: authorizedByAdmin(),
users: authorizedByAdmin(),
adminCommentsByApplicantRecordId: authorizedByAdmin(),
adminCommentById: authorizedByAdmin(),
},
Mutation: {
createEntity: authorizedByAllRoles(),
Expand Down
19 changes: 19 additions & 0 deletions backend/typescript/graphql/resolvers/adminCommentsResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AdminCommentDTO[]> => {
const adminComments =
await adminCommentService.getAdminCommentsByApplicantRecordId(
applicantRecordId,
);
return adminComments;
},
adminCommentById: async (
_parent: undefined,
{ id }: { id: string },
): Promise<AdminCommentDTO> => {
const adminComment = await adminCommentService.getAdminCommentById(id);
return adminComment;
},
},
Mutation: {
createAdminComment: async (
_parent: undefined,
Expand Down
7 changes: 7 additions & 0 deletions backend/typescript/graphql/types/adminCommentsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
49 changes: 49 additions & 0 deletions backend/typescript/services/implementations/adminCommentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,55 @@ const grabAdminComment = async (commentId: string): Promise<AdminComment> => {
class AdminCommentService implements IAdminCommentService {
/* eslint-disable class-methods-use-this */

async getAdminCommentsByApplicantRecordId(
applicantRecordId: string,
): Promise<AdminCommentDTO[]> {
let adminComments: AdminComment[] = [];
let adminCommentDTOs: Array<AdminCommentDTO> = [];
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<AdminCommentDTO> {
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<AdminCommentDTO> {
Expand Down
4 changes: 4 additions & 0 deletions backend/typescript/services/interfaces/adminCommentService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { AdminCommentDTO, CreateAdminCommentDTO } from "../../types";

interface IAdminCommentService {
getAdminCommentsByApplicantRecordId(
reviewedApplicantRecordId: string,
): Promise<AdminCommentDTO[]>;
getAdminCommentById(id: string): Promise<AdminCommentDTO>;
createAdminComment(content: CreateAdminCommentDTO): Promise<AdminCommentDTO>;
updateAdminComment(
commentId: string,
Expand Down
Loading