refactor(db): no callbacks
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-04-01 14:17:36 +02:00
parent 278346233d
commit 3da083de53
7 changed files with 38 additions and 83 deletions

View File

@ -5,5 +5,5 @@ module.exports = function insertSmartTag(smartTagFk, shelving, level) {
VALUES (?, ?, ?)
ON DUPLICATE KEY
UPDATE shelvingFk = ?, level = ?;`;
con.query(sql, [smartTagFk, shelving, level, shelving, level]);
return con.query(sql, [smartTagFk, shelving, level, shelving, level]);
};

View File

@ -2,8 +2,6 @@ const con = require('./connect');
function insertTicket(ticket, smartTag) {
const sql = `UPDATE vn.ticketCollection SET smartTagFk = ? WHERE ticketFk = ?`;
con.query(sql, [smartTag, ticket], function(err, result) {
if (err) throw err;
});
return con.query(sql, [smartTag, ticket]);
}
exports.insertTicket = insertTicket;

View File

@ -1,12 +0,0 @@
const con = require('./connect');
function maxWagon(collectionFk, callback) {
let sql = `SELECT MAX(tc.wagon) AS MaxWagons
FROM ticketCollection tc
WHERE tc.collectionFk = ${collectionFk}`;
con.query(sql, function(err, result, fields) {
callback(null, result);
});
}
exports.maxWagon = maxWagon;

View File

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

View File

@ -14,11 +14,11 @@ router.get('/:collectionFk', async(req, res) => {
module.exports = router;
async function insertTicket(consultaSql) {
async function insertTicket(collection) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
for (let i = 0; i < consultaSql.length; i++) {
for (let i = 0; i < collection.length; i++) {
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
@ -29,14 +29,14 @@ async function insertTicket(consultaSql) {
{
attrCategory: 'verdnatura',
attrName: 'withTicket',
barCode: consultaSql[i].shelvingFk + consultaSql[i].level, // Matricula + nivel
barCode: collection[i].shelvingFk + collection[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
productCode: collection[i].ticketFk, // Ticket
qrCode: collection[i].ticketFk,
custFeature1: collection[i].clientFk, // Cliente
custFeature2: collection[i].agencyFk, // Agencia de transporte
custFeature3: '', // collection[i].workerFk, // Trabajador
custFeature4: collection[i].wagon, // Wagon
}
]
},

View File

@ -1,44 +1,36 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
const select = require('../db/selectTicket');
const selectTicket = require('../db/selectTicket');
const config = require('../config');
const dataLogIn = require('../server');
const got = require('got');
router.get('/:ticket', async(req, res) => {
const ticket = req.params.ticket;
const ticketId = req.params.ticket;
const ticket = selectTicket(ticketId);
await insertFlash(ticket);
searchTicket(ticket);
res.json({message: 'SUCCESS'});
});
module.exports = router;
function searchTicket(ticket) {// parametro ticketFk
select.select(ticket, function(err, data) {
insertFlash(data);
async function insertFlash(ticket) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
await got.post('http://app.etiquetaselectronicas.com:9999/led/excuteLed', { // eslint-disable-line
json: {
storeId: config.storeId,
lightCololr: 8,
lightTime: 30,
targetExecution: ticket[0].shelvingFk + ticket[0].level + '/tagWithTicket',
lightFrequency: 1
},
responseType: 'json',
headers: {
'Authorization': key
}
});
}
function insertFlash(qrySql) {
const dataLogIn = require('../server');
const got = require('got');
(async() => {
const info = await dataLogIn.dataLogIn;
let key = info.data.token;
(async() => {
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/led/excuteLed', { // eslint-disable-line
json: {
storeId: config.storeId,
lightCololr: 8,
lightTime: 30,
targetExecution: qrySql[0].shelvingFk + qrySql[0].level + '/tagWithTicket',
lightFrequency: 1
},
responseType: 'json',
headers: {
'Authorization': key
}
});
})();
})();
}

View File

@ -1,18 +0,0 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
router.get('/:collectionFk', async(req, res) => {
const maxWagon = require('../db/maxWagon__');
// var collectionFk = '273449';
const collectionFk = req.params.collectionFk;
maxWagon.maxWagon(collectionFk, function(err, max) {
let maxWagons = max[0].MaxWagons;
res.json({
message: 'SUCCESS',
maxWagons: maxWagons
});
});
});
module.exports = router;