From 46b738e61c02b533989bdb6c9cae1f9d6a9bb4a6 Mon Sep 17 00:00:00 2001 From: Expand-sys Date: Wed, 9 Jun 2021 10:10:11 +1000 Subject: [PATCH] fix with ifs aswell --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 8becd23..9755483 100644 --- a/index.js +++ b/index.js @@ -219,15 +219,20 @@ app.get("/BankF", ensureAuthenticated, async function (req, res) { console.log(graphlog); let graphdata = '["transaction", "balance"]'; let currentbal = balance.value; - for (i = graphlog.length - 1; i > -1; i--) { - if (graphlog[i].from == req.session.user) { - currentbal = parseInt(currentbal) + parseInt(graphlog[i].amount); - graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]"; - } else { - currentbal = parseInt(currentbal) - parseInt(graphlog[i].amount); - graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]"; + if (graphlog) { + for (i = graphlog.length - 1; i > -1; i--) { + if (graphlog[i].from == req.session.user) { + currentbal = parseInt(currentbal) + parseInt(graphlog[i].amount); + graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]"; + } else { + currentbal = parseInt(currentbal) - parseInt(graphlog[i].amount); + graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]"; + } } + } else { + graphlog = undefined; } + if (logsent == 1 || logsent == -1 || logsent == null) { logsent = undefined; } else {