routes on files

This commit is contained in:
Adolfo Reyna
2021-08-07 20:49:02 -07:00
parent 4069054117
commit 5b9c0362e0
8 changed files with 222 additions and 101 deletions

View File

@@ -15,9 +15,7 @@ postDB = (DB)=>{
const id = DB.ObjectID(postid);
let update = {
$set:{
reactions:{
[userid]: reaction
},
["reactions." + userid]: reaction,
lastUpdated: new Date()
}
}
@@ -80,7 +78,15 @@ postDB = (DB)=>{
}
DB.getPosts = (userObj) => {
return DB.postCols.find().toArray().catch((err)=>{
return DB.postCols.find().sort({_id: -1}).toArray().catch((err)=>{
console.log(err);
return false;
});
}
DB.getPostsOfUser = (userId) => {
let userid = DB.ObjectID(userId);
return DB.postCols.find({userid}).sort({_id: -1}).toArray().catch((err)=>{
console.log(err);
return false;
});

31
dbTools/user.js Normal file
View File

@@ -0,0 +1,31 @@
const DBName = "EMI_SOCIAL";
const User = require("./../def/user.js");
let userProfileCache = {};
userDB = (DB)=>{
DB.profileCols = DB.db.db(DBName).collection("profiles");
DB.newProfile = (userObj) => {
console.log(userObj.toObj())
return DB.profileCols.insertOne(userObj.toObj()).catch((err)=>{
console.log(err);
return false;
});
}
DB.getProfile = async (userid)=>{
if(userProfileCache[userid]) return userProfileCache[userid];
const id = DB.ObjectID(userid)
let r = await DB.profileCols.findOne({userid: id}).catch((err)=>{
console.log(err);
return false;
});
if(r) userProfileCache[userid] = r;
return r;
}
}
module.exports = userDB;