const express = require('express'); const router = express.Router(); // eslint-disable-line const select = require('../db/selectCollection'); const insertTicketDB = require('../db/insertTicket'); router.get('/:collectionFk', async(req, res) => { const collectionFk = req.params.collectionFk; console.log(collectionFk); ticketShelving(collectionFk); res.json({message: 'SUCCESS'}); }); module.exports = router; function ticketShelving(collectionFk) {// parametro collectionFk select.selectCollectionSmartTag(collectionFk, function(err, data) { console.log('DATA', data); insertTicket(data); }); } function insertTicket(consultaSql) { console.log('CONSULTASQL:', 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++) { console.log('SHELVING: ', consultaSql[i].shelvingFk, consultaSql[i].level); 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].shelvingFk + consultaSql[i].level, // Matricula + nivel itemTitle: 'Etiqueta Con ticket', productCode: consultaSql[i].ticketFk, // Ticket qrCode: consultaSql[i].ticketFk, custFeature1: consultaSql[i].clientFk, // Cliente custFeature2: consultaSql[i].agencyFk, // Agencia de transporte custFeature3: '', // consultaSql[i].workerFk, // Trabajador custFeature4: consultaSql[i].wagon, // Wagon } ] }, responseType: 'json', headers: { 'Authorization': key } }); insertTicketDB.insertTicket(consultaSql[i].ticketFk, consultaSql[i].code); console.log(i, body); } })(); })(); } exports.insertTicket = insertTicket;