diff --git a/.gitignore b/.gitignore index 215737b..495aaa1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ config.js -node_modules \ No newline at end of file +node_modules +proba.js \ No newline at end of file diff --git a/bindShelving.js b/bindShelving.js new file mode 100644 index 0000000..5da3dbb --- /dev/null +++ b/bindShelving.js @@ -0,0 +1,50 @@ +const insert = require('./utilities/inserts'); + + +function smartTag(barcode, shelving, level){ + const got = require('got'); + const config = require('./config'); + (async() => { + insert.insertShelving(shelving, level); + (async() => { + const info = await config.info + let key = info.data.token; + + (async() => { + const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { + json: { + storeId: config.storeId, + tagItemBinds: [{ + eslBarcode: barcode, + itemBarcode: shelving + level + } + ] + }, + responseType: 'json', + headers: { + "Authorization": key + } + }) + console.log(body) + })(); + })(); + })(); +} + +///DATOS INTRODUCIDOS POR EL USUARIO//// +var barcode = "A0A3B820690F"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F) +var shelving = "BCD"; //valido = 3 CARACTERES LETRAS (A-Z) +var level = "1"; +////////////////////////////////////// + +if(insert.filter(barcode,"barcode")){ + if(insert.filter(shelving,"shelving")){ + smartTag(barcode, shelving, level); + } + else{ + console.log("¡MATRICULA INCORRECTA!") + } +} +else{ + console.log("¡CODIGO DE ETIQUETA INCORRECTO!") +} diff --git a/bindTicketShelving.js b/bindTicketShelving.js new file mode 100644 index 0000000..f86e4f8 --- /dev/null +++ b/bindTicketShelving.js @@ -0,0 +1,46 @@ + +const insert = require('./utilities/inserts'); + +var barcode = "A0A3B820690F"; +var shelving = "ABC";///introducida por el usuario +var collectionFk = '254'; + +var consultaSql1 = [ + { + id: 1025963, + ticketFk: 2516988, + level: 1,//en un futur no estaran + wagon: 0,//en un futur no estaran + nickname: 'FLORA&CO', + agencyModeFk: 'MRW',//Seria un numero + }, + { + id: 1025964, + ticketFk: 2542131, + level: 2, + wagon: 0, + nickname: 'MORRIS', + agencyModeFk: 'MRW'//Seria un numero + }, + { + id: 1025965, + ticketFk: 2542131, + level: 3, + wagon: 0, + nickname: 'MORRIS2', + agencyModeFk: 'MRW' + } +] + +function ticketCollection(){//parametro collectionFk + /// CONSULTA SQL PER A TINDRE ELS DIFERENTS ticketsColletion DE UN colletionFK (consiltaSql1) /// + /// CONSULTA SQL PER A CADA ticket DE CADA ticketCollection (consiltaSql2) /// + if(insert.filter(shelving,"shelving")){ + insert.insertTicket(consultaSql1, shelving) + } + else{ + console.log("¡MATRICULA INCORRECTA!") + } +} + +ticketCollection(); \ No newline at end of file diff --git a/filter.js b/filter.js new file mode 100644 index 0000000..819d581 --- /dev/null +++ b/filter.js @@ -0,0 +1,12 @@ +function filter(toFilter, type){ + let exp; + + if(type=="barcode"){ + exp = /^A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]$/ + } + if(type=="shelving"){ + exp = /^[A-Z][A-Z][A-Z]$/ + } + return exp.test(toFilter) +} +console.log(filter("A0A3B820690FF", "barcode")) diff --git a/insertTicket.js b/insertTicket.js index e95b7c3..00ab7a0 100644 --- a/insertTicket.js +++ b/insertTicket.js @@ -1,5 +1,5 @@ -const config = require('./config'); -const got = require('got'); + +const insertJson = require('./sqlToInsert'); var barcode = "A0A3B820690F"; var shelving = "ABC"; @@ -9,78 +9,33 @@ var consultaSql1 = [ { id: 1025963, ticketFk: 2516988, - level: 3, - wagon: 0, - - }, - { - id: 1025964, - ticketFk: 2542131, - level: 4, - wagon: 0 - }, - { - id: 1025965, - ticketFk: 2542131, - level: 5, - wagon: 0 - } -] -var consultaSql2 = [ - { - id: 1025963, + level: 1,//en un futur no estaran + wagon: 0,//en un futur no estaran nickname: 'FLORA&CO', - agencyModeFk: 'MRW'//Seria un numero + agencyModeFk: 'MRW',//Seria un numero }, { id: 1025964, + ticketFk: 2542131, + level: 2, + wagon: 0, nickname: 'MORRIS', agencyModeFk: 'MRW'//Seria un numero }, { id: 1025965, + ticketFk: 2542131, + level: 3, + wagon: 0, nickname: 'MORRIS2', - agencyModeFk: 'MRW'//Seria un numero + agencyModeFk: 'MRW' } ] function ticketCollection(){//parametro collectionFk /// CONSULTA SQL PER A TINDRE ELS DIFERENTS ticketsColletion DE UN colletionFK (consiltaSql1) /// /// CONSULTA SQL PER A CADA ticket DE CADA ticketCollection (consiltaSql2) /// - (async() => { - const info = await config.info - let key = info.data.token - let currentUser = info.data.currentUser; - (async() => { - for(var i=0;i { + 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/utilities/inserts.js b/utilities/inserts.js new file mode 100644 index 0000000..056df7b --- /dev/null +++ b/utilities/inserts.js @@ -0,0 +1,86 @@ +function insertTicket(sql, shelving){ + const config = require('../config'); + const got = require('got'); + (async() => { + const info = await config.info + let key = info.data.token + let currentUser = info.data.currentUser; + (async() => { + for(var i=0;i { + const info = await config.info + let key = info.data.token + let currentUser = info.data.currentUser; + (async() => { + const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { + json: { + agencyId: currentUser.agencyId, + merchantId: currentUser.merchantId, + storeId: currentUser.storeId, + unitName: currentUser.unitName, + itemList: [ + { + attrCategory: "verdnatura", + attrName: "sinTicket", + barCode: shelving + level,//Matricula + nivel + itemTitle: "Etiqueta Sin ticket", + } + ] + }, + responseType: 'json', + headers: { + "Authorization": key + } + }) + console.log(body) + })(); + })(); +} + + +function filter(toFilter, type){ + if(type=="barcode"){ + exp = /A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]/ + } + if(type=="shelving"){ + exp = /[A-F][A-F][A-F]/ + } + return exp.test(toFilter) +} + +exports.insertTicket = insertTicket; +exports.insertShelving = insertShelving; +exports.filter = filter;