From 33e72582d8340ab8ebd938121d5554678ba25d9e Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 3 Sep 2018 17:16:06 -0400 Subject: [PATCH] do some validation --- server.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 648c187..77d8e9f 100644 --- a/server.js +++ b/server.js @@ -197,19 +197,29 @@ server.get("/doc_add_gl_offset_single", bodyParser.json(), function (inReq, inRe { var l = 0; var tot = 0.00; + var bomb = false; console.log(inReq.body); x = inReq.body; + //add GL array x.GL = []; for (var i in x.item){ var line = x.item[i]; - x.GL.push(line); - tot = tot + line.amount; + if ((line.account != null) && (line.amount != null)) { + x.GL.push(line); + tot = tot + (line.amount || 0); + } + else { + bomb = true; + } + //add the whole line as-is + } + if (bomb = false) { + var ofs = JSON.parse(JSON.stringify(x.header)); + ofs.account = ofs.offset_account; + delete ofs.offset_account; + ofs.amount = -tot; + x.GL.push(ofs); } - var ofs = JSON.parse(JSON.stringify(x.header)); - ofs.account = ofs.offset_account; - delete ofs.offset_account; - ofs.amount = -tot; - x.GL.push(ofs); inRes.json(x); });