keyvalue storage using data in the profile

This commit is contained in:
Adolfo Reyna
2021-09-13 18:40:08 -07:00
parent 8797e5e984
commit f92aa70621
2 changed files with 28 additions and 0 deletions

View File

@@ -81,6 +81,24 @@ userDB = (DB) => {
});
}
DB.getData = async (profileid, key) => {
let profile = await DB.getProfile(profileid);
return profile.data[key];
}
DB.setData = async (profileid, key, value) => {
const _id = DB.ObjectID(profileid);
let update = {
$set:{
["data." + key]: value
}
}
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
console.log(err);
return false;
});
}
DB.addNotification = async (profileid, message) => {
const _id = DB.ObjectID(profileid);
let update = {

View File

@@ -104,6 +104,16 @@ DB.getDB.then((DB)=>{
});
});
router.post("/setData", (req, res) => {
const key = req.body.key;
const value = req.body.value;
const profileid = getProfileId(req);
DB.setData(profileid, key, value);
return res.json({
status: "ok",
});
});
router.get("/:id", async (req, res) => {
let profileId = req.params.id;
let profile = await DB.getProfile(profileId);