31 lines
789 B
JavaScript
31 lines
789 B
JavaScript
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; |