keyvalue storage using data in the profile
This commit is contained in:
@@ -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) => {
|
DB.addNotification = async (profileid, message) => {
|
||||||
const _id = DB.ObjectID(profileid);
|
const _id = DB.ObjectID(profileid);
|
||||||
let update = {
|
let update = {
|
||||||
|
|||||||
@@ -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) => {
|
router.get("/:id", async (req, res) => {
|
||||||
let profileId = req.params.id;
|
let profileId = req.params.id;
|
||||||
let profile = await DB.getProfile(profileId);
|
let profile = await DB.getProfile(profileId);
|
||||||
|
|||||||
Reference in New Issue
Block a user