implement proc type in /instance/resources

This commit is contained in:
2023-06-14 04:49:43 +00:00
parent 825b11cd56
commit 17837fbc29
3 changed files with 46 additions and 18 deletions

View File

@@ -35,16 +35,24 @@ export async function getUserResources(req, username) {
Object.keys(max).forEach((k) => {
avail[k] = max[k] - used[k];
});
return { used: used, max: max, avail: avail, units: dbResources };
return { used: used, max: max, avail: avail, resources: dbResources };
}
export async function approveResources(req, username, request) {
let avail = (await getUserResources(req, username)).avail;
let user = await getUserResources(req, username)
let avail = user.avail;
let resources = user.resources;
let max = user.max;
let approved = true;
Object.keys(request).forEach((key) => {
if (!(key in avail)) { // if requested resource is not in avail, block
approved = false;
}
else if (resources[key].type === "list") {
if (max[key].includes(request[key]) != resources[key].whitelist) {
approved = false;
}
}
else if (isNaN(avail[key]) || isNaN(request[key])) { // if either the requested or avail resource is NaN, block
approved = false;
}