INNER CODE UNIT · JavaScript

createComment

ihtasham42/social-media-app · controllers/commentControllers.js:7

const createComment = async (req, res) => {
  try {
    const postId = req.params.id;
    const { content, parentId, userId } = req.body;

    const post = await Post.findById(postId);

    if (!post) {
      throw new Error("Post not found");
    }

    if (cooldown.has(userId)) {
      throw new Error(
        "You are commenting too frequently. Please try again shortly."
      );
    }

    cooldown.add(userId);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…