▶️ 게시글 목록 조회 API 수정
router.get("/posts", (req, res) => {
res.status(200).json({ posts })
});
router.get("/posts", async (req, res) => {
const posts = await Posts.find({});
const postList = posts.map((post) => {
return {
postId: post.postId,
user: post.user,
title: post.title,
}
})
res.status(200).json({ post: postList })
})
module.exports = router;
TypeError: Router.use() requires a middleware function but got a Object
▶️ 게시글 수정 API
router.put("/posts/:postId", async (req, res) => {
const { postId } = req.params;
const { password, title, content } = req.body;
const modifiedPost = await Posts.find({ postId });
if (modifiedPost.length) {
await Posts.updateOne({ password: password },
{ $set: { title: title, content: content } })
}
res.status(200).json({ success: true });
})