diff --git a/dbTools/profile.js b/dbTools/profile.js index 002abeb..c90a39d 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -12,6 +12,17 @@ userDB = (DB) => { }); } + DB.updateProfile = async (profileid, profileObj) => { + let tempProfile = profileObj.toObj(); + const query = {_id: profileid}; + const update = {$set: {profile: tempProfile.profile}}; + let r = await DB.profileCols.updateOne(query, update).catch((err) => { + console.log(err); + return false; + }); + return r; + } + DB.getProfile = async (profileId) => { //if (userProfileCache[profileId] && !userProfileCache[profileId].isGroup) return userProfileCache[profileId]; const _id = DB.ObjectID(profileId); diff --git a/routes/profile.js b/routes/profile.js index b107966..5176a97 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -114,6 +114,18 @@ DB.getDB.then((DB)=>{ }); }); + router.post("/myProfile", async (req, res) => { + let profile = { + userid: getUserId(req), + profile: req.body + }; + let profileObj = new Profile(profile); //validates profile + DB.updateProfile(getProfileId(req), profileObj); + return res.json({ + status: "ok" + }); + }); + router.get("/:id", async (req, res) => { let profileId = req.params.id; let profile = await DB.getProfile(profileId);