const express = require('express'); const router = express.Router(); // eslint-disable-line const collectionSmartTag = require('../db/selectCollection'); const dataLogIn = require('../server'); const got = require('got'); const config = require('../config'); // const insertTicketDB = require('../db/insertTicket'); router.get('/:collectionFk', async(req, res) => { const collectionFk = req.params.collectionFk; const [collection] = await collectionSmartTag(collectionFk); if (!collection.length) return res.status(400).json({error: {code: 'emptyCollectionSmartTag', message: 'No hay datos'}}); await insertTicket(collection); res.json({message: 'SUCCESS'}); }); module.exports = router; async function insertTicket(collection) { const info = await dataLogIn.dataLogIn; const key = info.data.token; const currentUser = info.data.currentUser; for (let i = 0; i < collection.length; i++) { await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line json: { agencyId: currentUser.agencyId, merchantId: currentUser.merchantId, storeId: config.storeId, unitName: currentUser.unitName, itemList: [ { attrCategory: 'verdnatura', attrName: 'withTicket', barCode: collection[i].shelvingFk + collection[i].level, // Matricula + nivel itemTitle: 'tagWithTicket', productCode: collection[i].ticketFk, // Ticket qrCode: collection[i].ticketFk, custFeature1: collection[i].clientFk, // Cliente custFeature2: collection[i].agencyFk, // Agencia de transporte custFeature3: '', // collection[i].workerFk, // Trabajador custFeature4: collection[i].wagon, // Wagon } ] }, responseType: 'json', headers: { 'Authorization': key } }); } } exports.insertTicket = insertTicket;