fix bug in input validation

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-03-24 22:22:00 +00:00
parent eed39a007b
commit d135cec5ae

4
db.js
View File

@ -45,7 +45,7 @@ function allocateResources (user, resources) {
let newdb = {}; let newdb = {};
Object.assign(newdb, db); Object.assign(newdb, db);
Object.keys(resources).forEach((element) => { Object.keys(resources).forEach((element) => {
if(resources[element] instanceof Number && isFinite(resources[element])) { if(typeof(resources[element]) === "number" && isFinite(resources[element])) {
newdb[user][element] -= resources[element]; newdb[user][element] -= resources[element];
} }
else { else {
@ -73,7 +73,7 @@ function releaseResources (user, resources) {
let newdb = {}; let newdb = {};
Object.assign(newdb, db); Object.assign(newdb, db);
Object.keys(resources).forEach((element) => { Object.keys(resources).forEach((element) => {
if(resources[element] instanceof Number && isFinite(resources[element]) && resources[element]) { if(typeof(resources[element]) === "number" && isFinite(resources[element]) && resources[element]) {
newdb[user][element] += resources[element]; newdb[user][element] += resources[element];
} }
else { else {