diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a88a372 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\methods\\insertTicket.js" + } + ] +} \ No newline at end of file diff --git a/bindShelvingTag.js b/bindShelvingTag.js deleted file mode 100644 index 05a5fa4..0000000 --- a/bindShelvingTag.js +++ /dev/null @@ -1,28 +0,0 @@ -const insertShelving = require('./methods/insertShelving'); -const bindShelving = require('./methods/bindShelving'); -const filter = require('./utilities/filter'); -const insertDB = require('./db/insertDB') - -function bindShelvingTag(barcode, shelving, level){ - if(filter.isBarcode(barcode)){ - if(filter.isShelving(shelving)){ - let shelvingId = shelving + level; - insertShelving.insertShelving(shelvingId); - bindShelving.bindShelving(barcode, shelvingId); - insertDB.insertDB(barcode, shelving, level); - }else{ - console.log("¡MATRICULA INCORRECTA!") - } - }else{ - console.log("¡CODIGO DE ETIQUETA INCORRECTO!") - } -} -///DATOS INTRODUCIDOS POR EL USUARIO//// -var barcode = "A0A3B8224DBF"; //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/bindTicketShelving.js b/bindTicketShelving.js deleted file mode 100644 index 0a73f6a..0000000 --- a/bindTicketShelving.js +++ /dev/null @@ -1,24 +0,0 @@ -const insert = require('./methods/insertTicket'); -const filter = require('./utilities/filter'); -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 = '273449'; - -function ticketCollection(collectionFk){//parametro collectionFk - select.select(collectionFk, function(err,data){ - maxWagon.maxWagon(collectionFk,function(err,max){ - //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, max) - //}else{ - //console.log("¡MATRICULA INCORRECTA!") - //} - }); - }); -} - -ticketCollection(collectionFk); \ No newline at end of file diff --git a/db/insertDB.js b/db/insertDB.js index 59b4e25..13844e2 100644 --- a/db/insertDB.js +++ b/db/insertDB.js @@ -3,7 +3,7 @@ const con = require('./connect') function insertDB(barcode, shelving, level){ con.con.connect(function(err) { if (err) throw err; - console.log("Connected!"); + //console.log("Connected!"); var sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}') THEN UPDATE vn.smartTag @@ -16,7 +16,7 @@ function insertDB(barcode, shelving, level){ END IF;`; con.con.query(sql, function (err, result) { if (err) throw err; - console.log("1 record inserted"); + //console.log("1 record inserted"); }); }); } diff --git a/methods/bindShelving.js b/methods/bindShelving.js deleted file mode 100644 index b36971d..0000000 --- a/methods/bindShelving.js +++ /dev/null @@ -1,27 +0,0 @@ -const config = require('../config'); -const got = require('got'); - -function bindShelving(barcode, shelvingId){ - (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: shelvingId - } - ] - }, - responseType: 'json', - headers: { - "Authorization": key - } - }) - console.log("ETIQUETA: ",body) - })(); - })(); -} -exports.bindShelving = bindShelving; \ No newline at end of file diff --git a/methods/bindShelvingTag.js b/methods/bindShelvingTag.js new file mode 100644 index 0000000..c74fc20 --- /dev/null +++ b/methods/bindShelvingTag.js @@ -0,0 +1,100 @@ +const config = require('../config'); +const got = require('got'); +const filter = require('../utilities/filter'); +const insertDB = require('../db/insertDB'); +const express = require('express'); +const router = express.Router(); + +router.get('/', async(req, res) => { + ///DATOS INTRODUCIDOS POR EL USUARIO//// + var barcode = "A0A3B8224DBF"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F) + var shelving = "ABC"; //valido = 3 CARACTERES LETRAS (A-Z) + var level = "4"; + ////////////////////////////////////// + + const result = bindShelvingTag(barcode, shelving, level); + if(result == 'INVALID_PLATE'){ + res.json({message: 'MATRICULA INCORRECTA'}) + }else if (result == 'INVALID_TAG_CODE'){ + res.json({message: 'CODIGO DE ETIQUETA INCORRECTO'}) + }else{ + res.json({message: 'SUCCESS'}); + } + +}); + +module.exports = router; + +function bindShelvingTag(barcode, shelving, level){ + if(filter.isBarcode(barcode)){ + if(filter.isShelving(shelving)){ + let shelvingId = shelving + level; + insertShelving(shelvingId); + bindShelving(barcode, shelvingId); + insertDB.insertDB(barcode, shelving, level); + }else{ + //console.log("¡MATRICULA INCORRECTA!"); + return 'INVALID_PLATE'; + + } + }else{ + //console.log("¡CODIGO DE ETIQUETA INCORRECTO!") + return 'INVALID_TAG_CODE'; + } +} + +function insertShelving(shelvingId){ + (async() => { + 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: shelvingId,//Matricula + nivel + itemTitle: "Etiqueta Sin ticket", + } + ] + }, + responseType: 'json', + headers: { + "Authorization": key + } + }) + //console.log("CARRO: ",body) + })(); + })(); +} + +function bindShelving(barcode, shelvingId){ + (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: shelvingId + } + ] + }, + responseType: 'json', + headers: { + "Authorization": key + } + }) + //console.log("ETIQUETA: ",body) + })(); + })(); +} +exports.bindShelving = bindShelving; \ No newline at end of file diff --git a/methods/insertTicket.js b/methods/bindTicketShelving.js similarity index 60% rename from methods/insertTicket.js rename to methods/bindTicketShelving.js index 7ba9129..9de35bd 100644 --- a/methods/insertTicket.js +++ b/methods/bindTicketShelving.js @@ -1,3 +1,34 @@ +const express = require('express'); +const router = express.Router(); +const filter = require('../utilities/filter'); +const select = require('../db/selectDB'); +const maxWagon = require('../db/maxWagon'); + + +router.get('/:collectionFk', async(req, res) => { + //var shelving = "BCD";///introducida por el usuario O en leida de la bbdd? + //var collectionFk = '273449'; + const collectionFk = req.params.collectionFk; + ticketCollection(collectionFk); + res.json({message: 'SUCCESS'}) +}); + +module.exports = router; + +function ticketCollection(collectionFk){//parametro collectionFk + select.select(collectionFk, function(err,data){ + maxWagon.maxWagon(collectionFk,function(err,max){ + //aqui iria una función para pedir el numero de shelvings correspondientes + var shelving = ['ABC','DFG','HIJ'] + //if(filter.isShelving(shelving)){ + insertTicket(data, shelving, max) + //}else{ + //console.log("¡MATRICULA INCORRECTA!") + //} + }); + }); +} + function insertTicket(consultaSql, shelving, max){ const config = require('../config'); const got = require('got'); @@ -32,7 +63,8 @@ function insertTicket(consultaSql, shelving, max){ "Authorization": key } }) - console.log(body,consultaSql[i].Ticket,shelving[consultaSql[i].Wagon-1],consultaSql[i].Level.toString().charAt(j)) + return true; + //console.log(body,consultaSql[i].Ticket,shelving[consultaSql[i].Wagon-1],consultaSql[i].Level.toString().charAt(j)) } } })(); diff --git a/methods/insertShelving.js b/methods/insertShelving.js deleted file mode 100644 index 851d797..0000000 --- a/methods/insertShelving.js +++ /dev/null @@ -1,35 +0,0 @@ -const config = require('../config'); -const got = require('got'); - -function insertShelving(shelvingId){ - (async() => { - 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: shelvingId,//Matricula + nivel - itemTitle: "Etiqueta Sin ticket", - } - ] - }, - responseType: 'json', - headers: { - "Authorization": key - } - }) - console.log("CARRO: ",body) - })(); - })(); -} - -exports.insertShelving = insertShelving; \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..895ddd7 --- /dev/null +++ b/server.js @@ -0,0 +1,11 @@ +const express = require('express'); +const app = express(); +const port = 9999; + +app.use('/bindShelving', require('./methods/bindShelvingTag')); +app.use('/insertTicket', require('./methods/bindTicketShelving')); + + +app.listen(port, () => { + console.log(`Example app listening at http://localhost:${port}`) +});