Merge branch 'dev' of github.com:JoaquinPar/2800-202510-BBY14 into fix/account_details_update

This commit is contained in:
SowinskiBraeden committed 2025-05-14 12:13:04 -07:00
commit 1f3109a68f
5 files changed
+114 -75

No files matched your search

+22 -21
View File
@@ -101,18 +101,17 @@ module.exports = (middleware, users, plans, assets) => {
try {
const userPlansFromDB = await plans.find({ userId: new ObjectId(req.session.userId) }).toArray();
// Use a for...of loop for proper async/await behavior in series for updates
for (const plan of userPlansFromDB) {
const percentage = await calculatePlanProgress(plan, assets, req.session.userId);
await updatePlanProgressInDB(plan._id, percentage, plans); // Pass the 'plans' collection
const percentage = await calculatePlanProgress(plan, assets, req.session.user._id);
await updatePlanProgressInDB(plan._id, percentage, plans);
}
// Re-fetch plans to get updated progress for rendering
const updatedUserPlans = await plans.find({ userId: new ObjectId(req.session.userId) }).toArray();
const updatedUserPlans = await plans.find({ userId: new ObjectId(req.session.user._id) }).toArray();
res.render('plans', {
user: req.session.user,
plans: updatedUserPlans, // Send the most up-to-date plans
plans: updatedUserPlans,
geoData: req.session.geoData
});
} catch (err) {
@@ -141,16 +140,9 @@ module.exports = (middleware, users, plans, assets) => {
return res.status(status.NotFound).redirect('/plans');
}
// The plan.progress should be up-to-date from the database as it was updated in the /plans route
// or when assets/plans are modified. If an immediate recalculation for this specific view is absolutely needed,
// (e.g., if assets were modified without an immediate plan progress update elsewhere),
// you could do it here:
// const currentProgress = await calculatePlanProgress(plan, assets, req.session.user._id);
// plan.progress = currentProgress; // This would only update the 'plan' object for this render, not in DB
res.render('planDetail', {
user: req.session.user,
plan: plan, // This plan object will have the progress from the database
plan: plan,
geoData: req.session.geoData,
assets: userAssets,
suggestions: await suggestions.generateSuggestions(),
@@ -217,9 +209,10 @@ module.exports = (middleware, users, plans, assets) => {
}
});
router.get('/pun', async (req, res) => {
const pun = await suggestions.generatePun();
return res.status(status.Ok).json({ pun });
router.post('/fact', async (req, res) => {
const factInput = req.body.fact;
const fact = await suggestions.generateFact(factInput);
return res.status(status.Ok).json({ fact });
});
router.get('/more', (req, res) => {
@@ -659,11 +652,19 @@ module.exports = (middleware, users, plans, assets) => {
country = data.results[0].formatted_address;
let results = await getRates(country);
req.session.geoData = {
country: results.abbreviation,
toCurrencyRates: results.exRates,
geoData: req.session.geoData
if (!results.exRates) {
req.session.geoData = {
message: "error"
}
} else {
req.session.geoData = {
country: results.abbreviation,
toCurrencyRates: results.exRates,
geoData: req.session.geoData
}
}
}
return res.status(status.Ok).send({ data: req.session.geoData });