From 001224b9ce7444b99001b3bb565c01910ed1e987 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 30 Mar 2022 20:01:14 +1300 Subject: [PATCH] [WIP] Retrieve user options object --- server/userinfo.api.js | 14 +++++++++++++- server/userinfo.model.js | 24 +++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/server/userinfo.api.js b/server/userinfo.api.js index 2a4f560df..961dddedb 100644 --- a/server/userinfo.api.js +++ b/server/userinfo.api.js @@ -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; diff --git a/server/userinfo.model.js b/server/userinfo.model.js index 1adec1d7d..bc2ac4630 100644 --- a/server/userinfo.model.js +++ b/server/userinfo.model.js @@ -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);