Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
reginald-chand committed Jun 28, 2024
1 parent 6c87c07 commit 677ea51
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions server/controllers/comment/comment.controller.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export const commentController = async (request, response) => {
return response.status(404).json({ responseMessage: "Post not found." });
}

const existingPostIds = new Set(
existingPosts.map((post) => post._id.toString())
);

if (!existingPostIds.has(postId.toString())) {
return response.status(404).json({ responseMessage: "Post not found." });
}

for (const post of existingPosts) {
const existingCommentDocument = await CommentModel.findOne({
_id: { $eq: post._id },
Expand Down

0 comments on commit 677ea51

Please sign in to comment.