const express = require('express'); const router = express.Router(); // eslint-disable-line const select = require('../db/selectCollection'); const filter = require('../utilities/filter'); const insertTicketDB = require('../db/insertTicket'); router.get('/collectionFk', async(req, res) => { const collectionShelving = req.params.collectionShelving.split(','); const collectionFk = req.params.collectionFk; console.log(collectionShelving); console.log(collectionFk); if (filter.isShelving(collectionShelving)) { ticketShelving(collectionShelving, collectionFk); res.json({message: 'SUCCESS'}); } else res.json({message: 'SHELVING ERROR'}); }); module.exports = router; function ticketShelving(collectionShelving, collectionFk) {// parametro collectionFk select.select(collectionFk, function(err, data) { console.log(data); insertTicket(data, collectionShelving); }); } function insertTicket(consultaSql, shelving) { console.log(shelving); 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++) { for (let j = 0; j < consultaSql[i].Level.toString().length; j++) { console.log('SHELVING: ', shelving[consultaSql[i].Wagon - 1]); 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: shelving[consultaSql[i].Wagon - 1] + consultaSql[i].Level.toString().charAt(j), // Matricula + nivel itemTitle: 'Etiqueta Con ticket', productCode: consultaSql[i].Ticket, // Ticket custFeature1: consultaSql[i].Client, // Client custFeature2: consultaSql[i].Agency, // Agencia de transporte custFeature3: 0, // Agencia de transporte custFeature4: consultaSql[i].Worker, // Agencia de transporte } ] }, responseType: 'json', headers: { 'Authorization': key } }); insertTicketDB.insertTicket(consultaSql[i].Ticket, shelving[consultaSql[i].Wagon - 1], consultaSql[i].Level.toString().charAt(j)); console.log(i, body); } } })(); })(); } exports.insertTicket = insertTicket;