fix approveResources
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
864bec53ac
commit
1c2a0c7580
9
utils.js
9
utils.js
@ -40,16 +40,17 @@ export async function getUserResources (req, username) {
|
||||
|
||||
export async function approveResources(req, username, request) {
|
||||
let avail = (await getUserResources(req, username)).avail;
|
||||
let approved = true;
|
||||
Object.keys(request).forEach((key) => {
|
||||
if (!(key in avail)) { // if requested resource is not in avail, block
|
||||
return false;
|
||||
approved = false;
|
||||
}
|
||||
else if (isNaN(avail[key]) || isNaN(request[key])) { // if either the requested or avail resource is NaN, block
|
||||
return false;
|
||||
approved = false;
|
||||
}
|
||||
else if (avail[key] - request[key] < 0) { // if the avail resources is less than the requested resources, block
|
||||
return false;
|
||||
approved = false;
|
||||
}
|
||||
});
|
||||
return true; // if all requested resources pass, allow
|
||||
return approved; // if all requested resources pass, allow
|
||||
}
|
Loading…
Reference in New Issue
Block a user