Skip to content

Commit

Permalink
[WIP] Retrieve user options object
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Ambatte committed Mar 30, 2022
1 parent 73d899e commit 001224b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
14 changes: 13 additions & 1 deletion server/userinfo.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ const updateUserActivity = async (req, res)=>{
if(username) {
await UserInfoModel.updateActivity(username);
}
return res.redirect(301, '/');
return res.status(200).send();
};

const getUserOpts = async (req, res)=>{
console.log(req.account?.username);
username = req.account?.username;

if(username) {
const userOpts = await UserInfoModel.getUserOpts(username);
console.log(userOpts);
return res.status(200).send(userOpts);
}
};

router.get('/userinfo/updateActivity', updateUserActivity);
router.get('/userinfo/getUserOpts', getUserOpts);

module.exports = router;
24 changes: 13 additions & 11 deletions server/userinfo.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ UserInfoSchema.statics.get = function(username){
// return true;
// };

// // Get only the User options
// UserInfoSchema.statics.getUserOpts = function(username){
// return new Promise((resolve, reject)=>{
// const query = { username: username };

// UserInfo.findOne(query).lean().exec((err, user)=>{ //lean() converts results to JSObjects
// if(err) return reject('Can not find user');
// return resolve(user.options);
// });
// });
// };
// Get only the User options
// - Requires username (String)
// - Returns a JS object
UserInfoSchema.statics.getUserOpts = function(username){
return new Promise((resolve, reject)=>{
const query = { username: username };

UserInfo.findOne(query).lean().exec((err, user)=>{ //lean() converts results to JSObjects
if(err) return reject('Can not find user');
return resolve(user.options);
});
});
};

const UserInfo = mongoose.model('UserInfo', UserInfoSchema);

Expand Down

0 comments on commit 001224b

Please sign in to comment.