diff --git a/src/router/user.js b/src/router/user.js index 16c51f5..3bddc91 100644 --- a/src/router/user.js +++ b/src/router/user.js @@ -101,18 +101,16 @@ module.exports = (middleware, users, plans, assets) => { try { const userPlansFromDB = await plans.find({ userId: new ObjectId(req.session.user._id) }).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.user._id); - await updatePlanProgressInDB(plan._id, percentage, plans); // Pass the 'plans' collection + 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.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) { @@ -142,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(), @@ -218,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) => { diff --git a/src/util/suggestions.js b/src/util/suggestions.js index 2961014..2bfb957 100644 --- a/src/util/suggestions.js +++ b/src/util/suggestions.js @@ -2,10 +2,10 @@ const { GoogleGenAI } = require("@google/genai"); const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY }); -async function generatePun() { +async function generateFact(factInput) { const response = await ai.models.generateContent({ model: "gemini-2.0-flash", - contents: "Return a funny pun about investments, answer the pun only, no additional text.", + contents: `Generate a concise investment fact about "${factInput}". If "${factInput}" is not directly investment-related, provide a general, useful investment fact instead. Deliver only the fact itself, with no extra text or explanation.`, }); return response.text; } @@ -19,6 +19,6 @@ async function generateSuggestions() { } module.exports = { - generatePun, + generateFact, generateSuggestions }; diff --git a/src/views/partials/footer.ejs b/src/views/partials/footer.ejs index 2c04272..0f3bc65 100644 --- a/src/views/partials/footer.ejs +++ b/src/views/partials/footer.ejs @@ -1,7 +1,14 @@ -
- +
+ + @@ -13,21 +20,35 @@ - - + \ No newline at end of file