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

75 lines
3.0 KiB
JavaScript
Raw Normal View History

2021-03-18 10:04:32 +00:00
const express = require('express');
const router = express.Router();
const filter = require('../utilities/filter');
const select = require('../db/selectDB');
const maxWagon = require('../db/maxWagon');
router.get('/:collectionFk', async(req, res) => {
//var shelving = "BCD";///introducida por el usuario O en leida de la bbdd?
//var collectionFk = '273449';
const collectionFk = req.params.collectionFk;
ticketCollection(collectionFk);
res.json({message: 'SUCCESS'})
});
module.exports = router;
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
var shelving = ['ABC','DFG','HIJ']
//if(filter.isShelving(shelving)){
insertTicket(data, shelving, max)
//}else{
//console.log("¡MATRICULA INCORRECTA!")
//}
});
});
}
2021-03-16 11:25:32 +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() => {
const info = await config.info
let key = info.data.token
let currentUser = info.data.currentUser;
2021-03-15 09:37:07 +00:00
2021-03-11 15:38:22 +00:00
(async() => {
2021-03-12 15:57:49 +00:00
for(var i=0;i<consultaSql.length;i++){
2021-03-17 08:11:55 +00:00
for(var j=0;j<consultaSql[i].Level.toString().length;j++){
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', {
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
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
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
2021-03-18 10:04:32 +00:00
return true;
//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;