From 8659289bef75a2e4fa581efbb0968f20a52ac07d Mon Sep 17 00:00:00 2001 From: Wingysam Date: Wed, 21 Nov 2018 18:02:36 -0500 Subject: [PATCH] Fix removing first item removes last --- routes/wishlist/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/wishlist/index.js b/routes/wishlist/index.js index 66a9100..d23c021 100644 --- a/routes/wishlist/index.js +++ b/routes/wishlist/index.js @@ -86,7 +86,7 @@ module.exports = (db) => { return res.redirect(`/wishlist/${req.params.user}`); } docs.rows[i].doc.wishlist[j].pledgedBy = undefined; - if (docs.rows[i].doc.wishlist[j].addedBy === req.user._id) docs.rows[i].doc.wishlist.pop(j); + if (docs.rows[i].doc.wishlist[j].addedBy === req.user._id) docs.rows[i].doc.wishlist.splice(j, 1); await db.put(docs.rows[i].doc); req.flash('success', 'Successfully unpledged for item'); return res.redirect(`/wishlist/${req.params.user}`); @@ -105,7 +105,7 @@ module.exports = (db) => { const doc = await db.get(req.user._id); for (let i = 0; i < doc.wishlist.length; i++) { if (doc.wishlist[i].id === req.params.itemId) { - doc.wishlist.pop(i); + doc.wishlist.splice(i, 1); await db.put(doc); req.flash('success', 'Successfully removed from wishlist'); return res.redirect(`/wishlist/${req.params.user}`);