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

74 lines
3.1 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-18 10:38:05 +00:00
// const filter = require('../utilities/filter');
2021-03-18 10:04:32 +00:00
const select = require('../db/selectDB');
const maxWagon = require('../db/maxWagon');
router.get('/:collectionFk', async(req, res) => {
2021-03-18 10:38:05 +00:00
// var shelving = "BCD";///introducida por el usuario O en leida de la bbdd?
// var collectionFk = '273449';
2021-03-18 10:04:32 +00:00
const collectionFk = req.params.collectionFk;
ticketCollection(collectionFk);
2021-03-18 10:38:05 +00:00
res.json({message: 'SUCCESS'});
2021-03-18 10:04:32 +00:00
});
module.exports = router;
2021-03-18 10:38:05 +00:00
function ticketCollection(collectionFk) {// parametro collectionFk
select.select(collectionFk, function(err, data) {
maxWagon.maxWagon(collectionFk, function(err, max) {
// aqui iria una función para pedir el numero de shelvings correspondientes
let shelving = ['ABC', 'DFG', 'HIJ'];
// if(filter.isShelving(shelving)){
insertTicket(data, shelving, max);
// }else{
// console.log("¡MATRICULA INCORRECTA!")
// }
2021-03-18 10:04:32 +00:00
});
});
}
2021-03-18 10:38:05 +00:00
function insertTicket(consultaSql, shelving, max) {
2021-03-17 14:27:09 +00:00
const config = require('../config');
2021-03-11 15:38:22 +00:00
const got = require('got');
(async() => {
2021-03-18 10:38:05 +00:00
const info = await config.info;
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++) {
for (let j = 0; j < consultaSql[i].Level.toString().length; j++) {
2021-03-18 10:42:06 +00:00
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
2021-03-17 08:11:55 +00:00
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
2021-03-18 10:38:05 +00:00
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
2021-03-17 08:11:55 +00:00
}
]
},
responseType: 'json',
headers: {
2021-03-18 10:38:05 +00:00
'Authorization': key
2021-03-17 08:11:55 +00:00
}
2021-03-18 10:38:05 +00:00
});
2021-03-18 10:04:32 +00:00
return true;
2021-03-18 10:38:05 +00:00
// console.log(body,consultaSql[i].Ticket,shelving[consultaSql[i].Wagon-1],consultaSql[i].Level.toString().charAt(j))
2021-03-17 08:11:55 +00:00
}
2021-03-11 15:38:22 +00:00
}
})();
})();
}
exports.insertTicket = insertTicket;