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

68 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-03-18 10:04:32 +00:00
const express = require('express');
2021-03-18 10:42:06 +00:00
const router = express.Router(); // eslint-disable-line
2021-03-25 08:33:53 +00:00
const select = require('../db/selectCollection');
2021-03-26 15:26:17 +00:00
const insertTicketDB = require('../db/insertTicket');
2021-03-18 10:04:32 +00:00
2021-05-13 13:29:53 +00:00
router.get('/:collectionFk', async(req, res) => {
2021-03-18 15:30:28 +00:00
const collectionFk = req.params.collectionFk;
console.log(collectionFk);
2021-05-13 07:37:21 +00:00
ticketShelving(collectionFk);
2021-05-13 14:21:34 +00:00
res.json({message: 'SUCCESS'});
2021-03-18 10:04:32 +00:00
});
module.exports = router;
2021-05-13 07:37:21 +00:00
function ticketShelving(collectionFk) {// parametro collectionFk
select.selectCollectionSmartTag(collectionFk, function(err, data) {
2021-05-13 13:29:53 +00:00
console.log('DATA', data);
insertTicket(data);
2021-03-18 10:04:32 +00:00
});
}
function insertTicket(consultaSql) {
2021-03-18 15:24:51 +00:00
console.log('CONSULTASQL:', consultaSql);
2021-03-22 07:50:57 +00:00
console.log('CONSULTASQL_TAMAÑO:', consultaSql.length);
2021-03-18 12:56:34 +00:00
const dataLogIn = require('../server');
2021-03-11 15:38:22 +00:00
const got = require('got');
(async() => {
2021-03-18 12:56:34 +00:00
const info = await dataLogIn.dataLogIn;
2021-03-18 10:38:05 +00:00
let key = info.data.token;
2021-03-11 15:38:22 +00:00
let currentUser = info.data.currentUser;
2021-03-15 09:37:07 +00:00
2021-03-11 15:38:22 +00:00
(async() => {
2021-03-18 10:38:05 +00:00
for (let i = 0; i < consultaSql.length; i++) {
2021-05-13 13:29:53 +00:00
console.log('SHELVING: ', consultaSql[i].shelvingFk, consultaSql[i].level);
2021-03-18 10:42:06 +00:00
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
2021-05-13 13:29:53 +00:00
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
2021-07-01 06:55:17 +00:00
custFeature3: '', // consultaSql[i].workerFk, // Trabajador
custFeature4: consultaSql[i].wagon, // Wagon
2021-05-13 13:29:53 +00:00
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
2021-07-01 06:55:17 +00:00
insertTicketDB.insertTicket(consultaSql[i].ticketFk, consultaSql[i].code);
2021-05-13 13:29:53 +00:00
console.log(i, body);
2021-03-11 15:38:22 +00:00
}
})();
})();
}
exports.insertTicket = insertTicket;