minor change to user data to fit additional user data

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-04-20 21:39:41 +00:00
parent 9ccb9edf44
commit 3247989baa

View File

@ -44,13 +44,14 @@ app.post("/api/proxmox/*", async (req, res) => { // proxy endpoint for POST prox
}); });
async function getUserResources (req, username) { async function getUserResources (req, username) {
let used = await getUsedResources(req, getResources()); let dbResources = getResources();
let used = await getUsedResources(req, dbResources);
let max = getUser(username).resources.max; let max = getUser(username).resources.max;
avail = {}; avail = {};
Object.keys(max).forEach((k) => { Object.keys(max).forEach((k) => {
avail[k] = max[k] - used[k]; avail[k] = max[k] - used[k];
}); });
return {used: used, max: max, avail: avail}; return {used: used, max: max, avail: avail, units: dbResources};
} }
async function approveResources (request, avail) { async function approveResources (request, avail) {
@ -70,8 +71,7 @@ app.get("/api/user/resources", async(req, res) => {
// check auth // check auth
await checkAuth(req.cookies, res); await checkAuth(req.cookies, res);
let userResources = await getUserResources(req, req.cookies.username); let userResources = await getUserResources(req, req.cookies.username);
userResources.units = getResources(); res.status(200).send({resources: userResources});
res.status(200).send(userResources);
res.end(); res.end();
return; return;
}); });