This repository has been archived on 2024-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
smart-tag/methods/bindTicketShelving.js

69 lines
2.9 KiB
JavaScript

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: 0, // Luz LED
custFeature4: '', // consultaSql[i].workerFk, // Trabajador
custFeature5: consultaSql[i].wagon, // Wagon
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
insertTicketDB.insertTicket(consultaSql[i].ticketFk, consultaSql[i].shelvingFk, consultaSql[i].level);
console.log(i, body);
}
})();
})();
}
exports.insertTicket = insertTicket;