I am still fairly new to dynamic routing and although it makes sense, I am having issue implementing it correctly. Below is a function I want to grab the user's purchases from the database and export it as a csv. I had it working on local mongoDB but when I moved to Atlas for hosting, it only grabs the first person listed in the database and not the person logged in. Could I get some guidance on why my req.params is not working. Thank you in advance.
(This route would fall under app.use(/profile, profile) in the server)
profile.js
// DOWNLOADING CSV OF PURCHASES
router.get("/purchased-items/:id", csvAbuseLimiter, (req, res) => {
if (req.isAuthenticated()) {
User.findOne({ id: req.query.id }, (err, foundUser) => {
if (foundUser) {
console.log(foundUser);
const userPurchases = foundUser.purchases;
const fields = ["name", "order", "duration", "asset"];
const json2cvsParser = new Parser({ fields });
try {
const csv = json2cvsParser.parse(userPurchases);
res.attachment(`${req.user.username}-purchases.csv`);
res.status(200).send(csv);
req.flash("success", "successful download");
} catch (error) {
console.log("error:", error.message);
res.status(500).send(error.message);
}
}
});
}
});