From 834d52a2a2a7a8abd3454f857575c7f2cbae0813 Mon Sep 17 00:00:00 2001 From: pt Date: Tue, 12 May 2020 16:55:37 -0400 Subject: [PATCH] customer swap route will do nothing --- index.js | 44 +++++++++++++++++++++++++++++++++++++++++ route_sql/swap_cust.sql | 11 ++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index b8e7ae0..0f547a2 100644 --- a/index.js +++ b/index.js @@ -217,6 +217,50 @@ server.post('/swap', bodyParser.json(), function(req, res) { }; }) +server.post('/cust_swap', bodyParser.json(), function(req, res) { + + var sql = ""; + var w = ""; + var c = 1; + var d = 1; + var args = []; + var path = './route_sql/swap_cust.sql'; + + fs.readFile(path, 'utf8', function(err, data) { + if (!err) { + callback(data); + } else { + console.log("fatal error pulling sql file") + callback(err); + } + }); + + var callback = function(arg) { + sql = arg; + + //parse request body into a where clause + ({ c, w, d } = build_where(req, c, w, d, args)); + + //if there was no body sent, return with nothing + if (c == 1) { + res.send("no body was sent"); + return; + } + console.log(new Date().toISOString() + "-------------------------get swap fit:------------------------------") + console.log(req.body); + //parse the where clause into the main sql statement + sql = sql.replace(new RegExp("where_clause", 'g'), w); + sql = sql.replace(new RegExp("swap_doc", 'g'), JSON.stringify(req.body.swap)); + sql = sql.replace(new RegExp("replace_version", 'g'), req.body.scenario.version); + sql = sql.replace(new RegExp("replace_source", 'g'), req.body.source); + sql = sql.replace(new RegExp("replace_iterdef", 'g'), JSON.stringify(req.body)); + //execute the sql and send the result + console.log(sql); + res.json(null); + //Postgres.FirstRow(sql, [], res) + }; +}) + server.get('/list_changes', bodyParser.json(), function(req, res) { var sql = ""; diff --git a/route_sql/swap_cust.sql b/route_sql/swap_cust.sql index 46a66ab..8e1691a 100644 --- a/route_sql/swap_cust.sql +++ b/route_sql/swap_cust.sql @@ -17,17 +17,17 @@ target AS (SELECT $$swap_doc$$::jsonb swap) SELECT billto ,bill_r - ,bill_dba + ,bc.bvadr6 bill_dba ,shipto ,ship_r - ,ship_dba + ,sc.bvadr6 ship_dba --other stuff doesn't matter becuase it's getting overridden anyways FROM swap LEFT out JOIN lgdat.cust bc ON bc.bvcust = swap.bill_r LEFT out JOIN lgdat.cust sc ON - bc.bvcust = swap.ship_r + sc.bvcust = swap.ship_r ) --put bill to and ship to back together and join in channel, terms, descriptions, etc ,seg AS ( @@ -112,8 +112,9 @@ target AS (SELECT $$swap_doc$$::jsonb swap) FROM rlarp.osm_pool o CROSS JOIN log - INNER JOIN pl ON - pl.original = o.part + INNER JOIN swap ON + swap.bill_to = SUBSTRING(o.bill_cust_descr,1,8) + swap.bill_to = SUBSTRING(o.ship_cust_descr,1,8) WHERE -----------------scenario---------------------------- where_clause