diff --git a/bindShelvingTag.js b/bindShelvingTag.js index f202e51..520286d 100644 --- a/bindShelvingTag.js +++ b/bindShelvingTag.js @@ -4,11 +4,11 @@ const filter = require('./filter'); const insertDB = require('./db/insertDB') function bindShelvingTag(barcode, shelving, level){ - let shelvingId = shelving + level; if(filter.filterBarcode(barcode)){ if(filter.filterShelving(shelving)){ - bindShelving.bindShelving(barcode, shelvingId); - insertShelving.insertShelving(shelvingId); + var shelvingId = shelving + level; + //insertShelving.insertShelving(shelvingId); + //bindShelving.bindShelving(barcode, shelvingId); insertDB.insertDB(barcode, shelving, level); }else{ console.log("¡MATRICULA INCORRECTA!") @@ -18,9 +18,9 @@ function bindShelvingTag(barcode, shelving, level){ } } ///DATOS INTRODUCIDOS POR EL USUARIO//// -var barcode = "A0A3B8224DBF"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F) -var shelving = "BCD"; //valido = 3 CARACTERES LETRAS (A-Z) -var level = "1"; +var barcode = "A0A3B8224DFF"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F) +var shelving = "ABC"; //valido = 3 CARACTERES LETRAS (A-Z) +var level = "4"; ////////////////////////////////////// bindShelvingTag(barcode, shelving, level); diff --git a/db/insertDB.js b/db/insertDB.js index bcfa053..59b4e25 100644 --- a/db/insertDB.js +++ b/db/insertDB.js @@ -1,14 +1,23 @@ const con = require('./connect') function insertDB(barcode, shelving, level){ -con.con.connect(function(err) { - if (err) throw err; - console.log("Connected!"); - var sql = `INSERT INTO vn.smartTag (code, shelvingFk, level) VALUES ('${barcode}', '${shelving}', ${level})`; - con.con.query(sql, function (err, result) { + con.con.connect(function(err) { if (err) throw err; - console.log("1 record inserted"); + console.log("Connected!"); + var sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}') + THEN + UPDATE vn.smartTag + SET shelvingFk = '${shelving}', level = ${level} + WHERE code='${barcode}'; + ELSE + INSERT + INTO vn.smartTag (code, shelvingFk, level) + VALUES ('${barcode}', '${shelving}', ${level}); + END IF;`; + con.con.query(sql, function (err, result) { + if (err) throw err; + console.log("1 record inserted"); + }); }); - }); } exports.insertDB = insertDB; \ No newline at end of file diff --git a/encrypted.js b/encrypted.js index 738ce03..3d17c4a 100644 --- a/encrypted.js +++ b/encrypted.js @@ -14,4 +14,4 @@ const encryptPassword = async(password) => { return crypto.publicEncrypt(externKey, buffer).toString("base64"); }; -exports.encryptPassword = encryptPassword; \ No newline at end of file +exports.encryptPassword = encryptPassword; diff --git a/insertShelving.js b/insertShelving.js index 00298ff..112da45 100644 --- a/insertShelving.js +++ b/insertShelving.js @@ -1,7 +1,7 @@ const config = require('./config'); const got = require('got'); -function insertShelving(shelving, level){ +function insertShelving(shelvingId){ (async() => { const info = await config.info let key = info.data.token