diff --git a/bindShelvingTag.js b/bindShelvingTag.js index b6db2fe..cbf42ce 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){ - if(filter.filterBarcode(barcode)){ - if(filter.filterShelving(shelving)){ + if(filter.isBarcode(barcode)){ + if(filter.isShelving(shelving)){ bindShelving.bindShelving(barcode, shelving, level); insertShelving.insertShelving(shelving, level); - insertDB.insertDB(barcode, shelving, level); + //insertDB.insertDB(barcode, shelving, level); }else{ console.log("¡MATRICULA INCORRECTA!") } diff --git a/bindTicketShelving.js b/bindTicketShelving.js index 591e18d..b407cf6 100644 --- a/bindTicketShelving.js +++ b/bindTicketShelving.js @@ -1,20 +1,25 @@ const insert = require('./insertTicket'); const filter = require('./filter'); -const select = require('./db/selectDB') +const select = require('./db/selectDB'); +const maxWagon = require('./db/maxWagon'); var barcode = "A0A3B820690F"; -var shelving = "BCD";///introducida por el usuario O en leida de la bbdd? -var collectionFk = '254'; +//var shelving = "BCD";///introducida por el usuario O en leida de la bbdd? +var collectionFk = '274286'; -function ticketCollection(collectionFk, shelving){//parametro collectionFk +function ticketCollection(collectionFk){//parametro collectionFk select.select(collectionFk, function(err,data){ - if(filter.filterShelving(shelving)){ - insert.insertTicket(data, shelving) - } - else{ - console.log("¡MATRICULA INCORRECTA!") - } + maxWagon.maxWagon(collectionFk,function(err,max){ + console.log('Entra') + //aqui iria una función para pedir el numero de shelvings correspondientes + var shelving = ['ABC','DFG','HIJ'] + //if(filter.isShelving(shelving)){ + insert.insertTicket(data, shelving, 1) + //}else{ + //console.log("¡MATRICULA INCORRECTA!") + //} + }); }); } -ticketCollection(collectionFk, shelving); \ No newline at end of file +ticketCollection(collectionFk); \ No newline at end of file diff --git a/db/db.sql b/db/db.sql index 39af70f..8e74c18 100644 --- a/db/db.sql +++ b/db/db.sql @@ -3,8 +3,11 @@ CREATE TABLE vn.smartTag ( shelvingFk varchar(10) NULL, `level` int(11) NULL, CONSTRAINT `PRIMARY` PRIMARY KEY (code) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8 -COLLATE=utf8_unicode_ci; + ) + ENGINE=InnoDB + DEFAULT CHARSET=utf8 + COLLATE=utf8_unicode_ci; +ALTER TABLE vn.smartTag MODIFY COLUMN shelvingFk varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL NULL; + +ALTER TABLE vn.smartTag ADD CONSTRAINT smartTag_FK FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code); diff --git a/db/maxWagon.js b/db/maxWagon.js new file mode 100644 index 0000000..3eb84a0 --- /dev/null +++ b/db/maxWagon.js @@ -0,0 +1,14 @@ +const con = require('./connect') + +function maxWagon(collectionFk, callback){ + + let consSql = `SELECT MAX(tc.wagon) + FROM ticketCollection tc + WHERE tc.collectionFk = ${collectionFk}`; + con.con.query(consSql, function (err, result, fields) { + console.log(result); + callback(null,result); + }); +} + +exports.maxWagon = maxWagon; \ No newline at end of file diff --git a/encrypted.js b/encrypted.js deleted file mode 100644 index 738ce03..0000000 --- a/encrypted.js +++ /dev/null @@ -1,17 +0,0 @@ -const crypto = require('crypto'); -const got = require('got'); -const config = require('./config'); - -const encryptPassword = async(password) => { - const { body } = await got.get('http://app.etiquetaselectronicas.com:9999/user/getErpPublicKey', { - }); - const publicKey=`-----BEGIN PUBLIC KEY-----\n${JSON.parse(body).data}\n-----END PUBLIC KEY-----`; - const externKey = { - key: publicKey, - padding: crypto.constants.RSA_PKCS1_PADDING - }; - let buffer = Buffer.from(password); - return crypto.publicEncrypt(externKey, buffer).toString("base64"); -}; - -exports.encryptPassword = encryptPassword; \ No newline at end of file diff --git a/filter.js b/filter.js index 0d0df2c..3b5d41d 100644 --- a/filter.js +++ b/filter.js @@ -1,10 +1,10 @@ -function filterBarcode(toFilter){ +function isBarcode(toFilter){ const exp = /^A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]$/ return exp.test(toFilter) } -function filterShelving(toFilter){ +function isShelving(toFilter){ const exp = /^[A-Z][A-Z][A-Z]$/ return exp.test(toFilter) } -exports.filterBarcode = filterBarcode; -exports.filterShelving = filterShelving; \ No newline at end of file +exports.isBarcode = isBarcode; +exports.isShelving = isShelving; \ No newline at end of file diff --git a/insertTicket.js b/insertTicket.js index 3cdccf5..4f7f371 100644 --- a/insertTicket.js +++ b/insertTicket.js @@ -1,4 +1,4 @@ -function insertTicket(consultaSql, shelving){ +function insertTicket(consultaSql, shelving, max){ const config = require('./config'); const got = require('got'); (async() => { @@ -8,31 +8,33 @@ function insertTicket(consultaSql, shelving){ (async() => { for(var i=0;i { const { body } = await got.get('http://app.etiquetaselectronicas.com:9999/user/getErpPublicKey', { @@ -14,6 +14,4 @@ const encryptPassword = async(password) => { return crypto.publicEncrypt(externKey, buffer).toString("base64"); }; -//rebase - exports.encryptPassword = encryptPassword; \ No newline at end of file