fix bug in input validation
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
f34d9ae523
commit
6bda62ae15
4
db.js
4
db.js
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user