问题描述
我只想喜欢一个引文,或者不喜欢我已经喜欢的引文。所以首先我找到报价,然后我检查我是否已经喜欢这个报价,如果不是那么我喜欢,否则我不喜欢。
我有一个像下面这样的路由器
router.put('/:quoteId',isAuth,quotesController.likeQuote);
likeQuote 方法如下
module.exports.likeQuote = (req,res,next) => {
const quoteId = req.params.quoteId;
const userId = req.userId;
Quote.findById(quoteId)
.then((quote) => {
if (quote.likes.indexOf(userId) == -1) {
quote.likes.push(userId);
} else {
quote.likes.pull(userId);
}
return quote.save();
})
.then((updatedQuote) => {
res.status(201).json({ message: 'You liked the post!' });
})
.catch((err) => {
err.statusCode = 500;
next(err);
});
但我的问题是,我只想知道 PUT 和 PATCH 是如何工作的?我认为我们应该发送 PUT 中的所有字段,而不是 PATCH 方法中的所有字段,但在我的情况下,我什至不发送任何字段,并且两者都可以正常工作。这是怎么发生的?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)