Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/api/products', (req, res) => {
- let products = [];
- let id = null;
- let cart = JSON.parse(req.body.cart);
- if (!cart) return res.json(products);
- // TODO: replace for loop with .map
- for (var i = 0; i < data.products.length; i++) {
- id = data.products[i].id.toString();
- if (cart.hasOwnProperty(id)) {
- data.products[i].qty = cart[id];
- products.push(data.products[i]);
- }
- }
- return res.json(products);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement