From e13678ad563cb61d03ff9931cd3cd8aa229310b9 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Fri, 20 Feb 2026 22:05:43 -0500 Subject: [PATCH] Fix profile update persistence and stale cache --- dbTools/profile.js | 5 ++++- routes/profile.js | 32 ++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/dbTools/profile.js b/dbTools/profile.js index e1f3dcf..f2b2ac6 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -23,7 +23,9 @@ userDB = (DB) => { DB.updateProfile = async (profileid, profileObj) => { let tempProfile = profileObj.toObj(); - const query = { _id: profileid }; + if (!DB.ObjectID.isValid(profileid)) return false; + const _id = DB.ObjectID(profileid); + const query = { _id }; const update = { $set: { profile: tempProfile.profile, @@ -34,6 +36,7 @@ userDB = (DB) => { console.log(err); return false; }); + if (userProfileCache[profileid]) delete userProfileCache[profileid]; return r; } diff --git a/routes/profile.js b/routes/profile.js index 8e65b00..b9f7de4 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -760,16 +760,28 @@ DB.getDB.then((DB) => { * type: string */ router.post("/myProfile", async (req, res) => { - let profile = { - userid: getUserId(req), - profile: req.body.profile, - data: req.body.data - }; - let profileObj = new Profile(profile); //validates profile - DB.updateProfile(getProfileId(req), profileObj); - return res.json({ - status: "ok" - }); + try { + let profile = { + userid: getUserId(req), + profile: req.body.profile, + data: req.body.data + }; + let profileObj = new Profile(profile); //validates profile + const updateRes = await DB.updateProfile(getProfileId(req), profileObj); + if (!updateRes || !updateRes.matchedCount) { + return res.status(400).json({ + status: "Could not update profile" + }); + } + return res.json({ + status: "ok" + }); + } catch (error) { + console.error("Error updating myProfile", error); + return res.status(500).json({ + status: "Internal server error" + }); + } }); /**