From fba0fdc0a2d360e18ee7ec311545f25079231aa3 Mon Sep 17 00:00:00 2001 From: llopis15 Date: Thu, 25 Mar 2021 13:38:48 +0100 Subject: [PATCH] flashOn added --- methods/bindShelvingTag.js | 15 +++++----- methods/flashOn.js | 59 ++++++++++++++++++++++++++++++++++++++ server.js | 1 + 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 methods/flashOn.js diff --git a/methods/bindShelvingTag.js b/methods/bindShelvingTag.js index 8442beb..55ad179 100644 --- a/methods/bindShelvingTag.js +++ b/methods/bindShelvingTag.js @@ -4,6 +4,7 @@ const filter = require('../utilities/filter'); const config = require('../config'); const insertDB = require('../db/insertDB'); const express = require('express'); +const {con} = require('../db/connect'); const router = express.Router(); // eslint-disable-line router.get('/:barcode&:shelving&:level', async(req, res) => { @@ -11,7 +12,7 @@ router.get('/:barcode&:shelving&:level', async(req, res) => { const shelving = req.params.shelving;// valido = 3 CARACTERES LETRAS (A-Z) const level = req.params.level; console.log(barcode); - console.log(shelving, level); + console.log(shelving + level); const result = bindShelvingTag(barcode, shelving, level); if (result == 'INVALID_PLATE') @@ -28,8 +29,7 @@ function bindShelvingTag(barcode, shelving, level) { if (filter.isBarcode(barcode)) { if (filter.isShelving(shelving)) { let shelvingId = shelving + level; - insertShelving(shelvingId); - bindShelving(barcode, shelvingId); + insertShelving(shelvingId, barcode); insertDB.insertDB(barcode, shelving, level); } else return 'INVALID_PLATE'; @@ -37,10 +37,9 @@ function bindShelvingTag(barcode, shelving, level) { return 'INVALID_TAG_CODE'; } -function insertShelving(shelvingId) { +async function insertShelving(shelvingId, barcode) { (async() => { const info = await dataLogIn.dataLogIn; - console.log(info); let key = info.data.token; let currentUser = info.data.currentUser; (async() => { @@ -64,11 +63,13 @@ function insertShelving(shelvingId) { 'Authorization': key } }); + await bindShelving(barcode, shelvingId); + console.log('Insert Shelving:', body); })(); })(); } -function bindShelving(barcode, shelvingId) { +async function bindShelving(barcode, shelvingId) { (async() => { const info = await dataLogIn.dataLogIn; let key = info.data.token; @@ -87,7 +88,7 @@ function bindShelving(barcode, shelvingId) { 'Authorization': key } }); - console.log(body); + console.log('Bind', body); })(); })(); } diff --git a/methods/flashOn.js b/methods/flashOn.js new file mode 100644 index 0000000..28f7b1b --- /dev/null +++ b/methods/flashOn.js @@ -0,0 +1,59 @@ +const express = require('express'); +const router = express.Router(); // eslint-disable-line +const select = require('../db/selectTicket'); + +router.get('/:ticket', async(req, res) => { + const ticket = req.params.ticket; + console.log(ticket); + searchTicket(ticket); +}); + +module.exports = router; + +function searchTicket(ticket) {// parametro collectionFk + select.select(ticket, function(err, data) { + console.log(data); + insertFlash(data); + }); +} + +function insertFlash(consultaSql) { + console.log('CONSULTASQL_TAMAÑO:', consultaSql.length); + const dataLogIn = require('../server'); + const got = require('got'); + (async() => { + const info = await dataLogIn.dataLogIn; + let key = info.data.token; + let currentUser = info.data.currentUser; + + (async() => { + for (let i = 0; i < consultaSql.length; i++) { + const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line + json: { + agencyId: currentUser.agencyId, + merchantId: currentUser.merchantId, + storeId: currentUser.storeId, + unitName: currentUser.unitName, + itemList: [ + { + attrCategory: 'verdnatura', + attrName: 'conTicket', + barCode: consultaSql[i].Shelving + consultaSql[i].Level, // Matricula + nivel + itemTitle: 'Etiqueta Con ticket', + productCode: consultaSql[i].Ticket, // Ticket + custFeature1: consultaSql[i].Client, // Client + custFeature2: consultaSql[i].Agency, // Agencia de transporte + custFeature3: 1 + } + ] + }, + responseType: 'json', + headers: { + 'Authorization': key + } + }); + console.log(body); + } + })(); + })(); +} diff --git a/server.js b/server.js index f849431..9c29227 100644 --- a/server.js +++ b/server.js @@ -9,6 +9,7 @@ exports.dataLogIn = dataLogIn; app.use('/getNumShelving', require('./methods/setCollection')); app.use('/insertTicket', require('./methods/bindTicketShelving')); app.use('/bindShelving', require('./methods/bindShelvingTag')); +app.use('/flashOn', require('./methods/flashOn')); app.listen(port, () => { console.log(`Example app listening at http://localhost:${port}`);