refactor(insertTicket): bindTicketShelving and selectCollection
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-03-31 12:27:30 +02:00
parent da09c4b346
commit 4e65fb42d0
4 changed files with 39 additions and 58 deletions

View File

@ -1,12 +1,7 @@
const con = require('./connect');
function selectCollectionSmartTag(collectionFk, callback) {
module.exports = function selectCollectionSmartTag(collectionFk) {
const sql = `SELECT * FROM vn.collectionSmartTag WHERE collectionFk = ?;`;
con.query(sql, collectionFk, function(err, result, fields) {
if (err) throw err;
callback(null, result);
});
}
exports.selectCollectionSmartTag = selectCollectionSmartTag;
return con.query(sql, collectionFk);
};

View File

@ -1,61 +1,51 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
const select = require('../db/selectCollection');
const collectionSmartTag = require('../db/selectCollection');
const dataLogIn = require('../server');
const got = require('got');
// const insertTicketDB = require('../db/insertTicket');
router.get('/:collectionFk', async(req, res) => {
const collectionFk = req.params.collectionFk;
ticketShelving(collectionFk);
const [collection] = await collectionSmartTag(collectionFk);
await insertTicket(collection);
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
async function insertTicket(consultaSql) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
for (let i = 0; i < consultaSql.length; i++) {
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;

View File

@ -4,11 +4,8 @@ const config = require('./config');
const app = express();
const dataLogIn = logIn;
exports.dataLogIn = dataLogIn;
// con.connect(function(err) {});
// app.use('/getNumShelving', require('./methods/setCollection__'));
app.use('/bindShelving', require('./methods/bindShelvingTag')); // smartTagFk, shelving, level
app.use('/insertTicket', require('./methods/bindTicketShelving')); // collectionFk

View File

@ -1,6 +1,5 @@
const crypto = require('crypto');
const got = require('got');
// const config = require('../config');
const encryptPassword = async password => {
const {body} = await got.get('http://app.etiquetaselectronicas.com:9999/user/getErpPublicKey', {