routes on files
This commit is contained in:
@@ -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
31
dbTools/user.js
Normal 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;
|
||||
Reference in New Issue
Block a user