fix bug in validation

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-03-24 22:10:17 +00:00
parent 7272bbe683
commit 3a823c85ba
2 changed files with 5 additions and 3 deletions

4
db.js
View File

@ -25,10 +25,12 @@ function init () {
function requestResources (user, resources) {
let approved = true;
Object.keys(resources).forEach((element) => {
if(!db[user][element]) { // if the resource does not exist in the user's entry, assume the user is not allowed to use it
if(!(element in db[user])) { // if the resource does not exist in the user's entry, assume the user is not allowed to use it
console.log("a")
approved = false;
}
else if (db[user][element] - resources[element] < 0) {
console.log("b")
approved = false;
}
});

View File

@ -262,8 +262,8 @@ app.post("/api/resources", async (req, res) => {
let currentConfig = await requestPVE(`${vmpath}/config`, "GET", null, null, pveAPIToken);
let request = {
cores: Number(req.body.cores) - currentConfig.data.data.cores,
memory: Number(req.body.memory) - currentConfig.data.data.memory
cores: Number(req.body.cores) - Number(currentConfig.data.data.cores),
memory: Number(req.body.memory) - Number(currentConfig.data.data.memory)
};
if (!requestResources(req.cookies.username, request)) { // check resource approval
res.status(500).send({auth: auth, data:{request: request, error: `Not enough resources to satisfy request.`}});