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

62 lines
2.4 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;
ticketShelving(collectionFk);
res.json({message: 'SUCCESS'});
});
module.exports = router;
function ticketShelving(collectionFk) {// parametro collectionFk
select.selectCollectionSmartTag(collectionFk, function(err, data) {
insertTicket(data);
});
}
function insertTicket(consultaSql) {
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: 'withTicket',
barCode: consultaSql[i].shelvingFk + consultaSql[i].level, // Matricula + nivel
itemTitle: 'tagWithTicket',
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
}
});
}
})();
})();
}
exports.insertTicket = insertTicket;