diff --git a/db/insertSmartTag.js b/db/insertSmartTag.js index cd23c63..99fb33f 100644 --- a/db/insertSmartTag.js +++ b/db/insertSmartTag.js @@ -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]); }; diff --git a/db/insertTicket.js b/db/insertTicket.js index 385b73e..6f8e09d 100644 --- a/db/insertTicket.js +++ b/db/insertTicket.js @@ -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; diff --git a/db/maxWagon__.js b/db/maxWagon__.js deleted file mode 100644 index 5aa8230..0000000 --- a/db/maxWagon__.js +++ /dev/null @@ -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; diff --git a/db/selectTicket.js b/db/selectTicket.js index dab6eb9..38b3a68 100644 --- a/db/selectTicket.js +++ b/db/selectTicket.js @@ -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); +}; diff --git a/methods/bindTicketShelving.js b/methods/bindTicketShelving.js index cb2e9f0..02f8e5a 100644 --- a/methods/bindTicketShelving.js +++ b/methods/bindTicketShelving.js @@ -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 } ] }, diff --git a/methods/flashOn.js b/methods/flashOn.js index 4b5f16e..738c366 100644 --- a/methods/flashOn.js +++ b/methods/flashOn.js @@ -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 - } - }); - })(); - })(); -} diff --git a/methods/setCollection__.js b/methods/setCollection__.js deleted file mode 100644 index 404b45a..0000000 --- a/methods/setCollection__.js +++ /dev/null @@ -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; -