router.delete('/remove/:id', auth, async(req, res) => {
await req.user.removeFromCart(req.params.id);
const user = await req.user.populate('cart.items.productId').execPopulate();
const cartProducts = mapCartItems(user.cart);
const cart = {
cartProducts,
price: computePrice(cartProducts)
}
res.status(200).json(cart)
})
<form class="cart__product-desc-form" action="/remove/:id" method="POST">
<input class="cart__product-desc-remove-product js-remove" type="submit" data-csrf="#{csrf}" data-id="#{product.id}" value="Удалить" />
<input type="hidden" name="_csrf" value="csrf" />
</form>
router.get('/', async(req, res) => {
const products = await Product.find()
.populate('email name')
.select('nowPrice oldPrice sale size title img')
res.render('shop', {
title: 'Syc-store магазин',
isProducts: true,
products
})
})