router.delete('/:postId', async (req, res, next) => {
  // DELETE /post/10
  try {
    await Post.destroy({
      where: { id: req.params.postId },
    });
    res.json({ PostId: req.params.postId });
  } catch (error) {
    console.error(error);
    next(error);
  }
});

이 상황은 누구나 게시물을 지울 수 있다

UserId: req.user.id

where 조건문에 위의 코드도 넣어주면 완벽해진다

⇒ 요청받은 게시물의 아이디면서, 내 아이디로 작성된 글이면 삭제한다

⇒ 실수로 남의 글을 삭제하게 한다 (방지)

router.patch('/nickname', isLoggedIn, async (req, res, next) => {
  try {
    await User.update(
      {
        nickname: req.body.nickname,
      },
      {
        where: { id: req.user.id },
      },
    );
  } catch (error) {
    console.error(err);
    next(err);
  }
});

내 닉네임을 프론트에서 받은 닉네임(req.body.nickname)으로 수정한다

router.delete('/:postId', isLoggedIn, async (req, res, next) => {
  // DELETE /post/10
  try {
    await Post.destroy({
      where: { id: req.params.postId, UserId: req.user.id },
    });
    res.status(200).json({ PostId: parseInt(req.params.postId, 10) });
  } catch (error) {
    console.error(error);
    next(error);
  }
});

parseInt(req.params.postId, 10)

이 과정을 거쳐야 하는 이유 ⇒ params는 항상 문자열이다

새로운 회원

id: [email protected]

pw: ‘ ‘