working on users having multiple profiles
This commit is contained in:
@@ -77,8 +77,13 @@ postDB = (DB)=>{
|
||||
});
|
||||
}
|
||||
|
||||
DB.getPosts = (userid) => {
|
||||
let query = userid ? {userid} : {};
|
||||
DB.getPosts = (profileId) => {
|
||||
let query = profileId ? {
|
||||
$or: [
|
||||
{_id: profileId},
|
||||
{toUser: profileId}
|
||||
]
|
||||
} : {};
|
||||
return DB.postCols.find(query).sort({_id: -1}).toArray().catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
|
||||
49
dbTools/profile.js
Normal file
49
dbTools/profile.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const DBName = "EMI_SOCIAL";
|
||||
|
||||
let userProfileCache = {};
|
||||
|
||||
userDB = (DB) => {
|
||||
DB.profileCols = DB.db.db(DBName).collection("profiles");
|
||||
|
||||
DB.newProfile = (profileObj) => {
|
||||
return DB.profileCols.insertOne(profileObj.toObj()).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getProfile = async (profileId) => {
|
||||
if (userProfileCache[profileId]) return userProfileCache[profileId];
|
||||
const _id = DB.ObjectID(profileId);
|
||||
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
if (r) userProfileCache[profileId] = r;
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.getProfiles = async (userId) => {
|
||||
const userid = DB.ObjectID(userId);
|
||||
return await DB.profileCols.find({ userid }).toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.latestProfile = async (userId) => {
|
||||
const userid = DB.ObjectID(userId);
|
||||
let r = await DB.profileCols.find({ userid })
|
||||
.sort({ lastUpdate: -1 }).limit(1)
|
||||
.toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
if (r[0]) userProfileCache[r[0].id] = r[0];
|
||||
return r[0];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = userDB;
|
||||
@@ -1,31 +0,0 @@
|
||||
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