fix bug in validation
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
33deb01b74
commit
bd845b47f0
4
db.js
4
db.js
@ -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;
|
||||
}
|
||||
});
|
||||
|
4
main.js
4
main.js
@ -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.`}});
|
||||
|
Loading…
Reference in New Issue
Block a user