code restructured

This commit is contained in:
llopis15 2021-03-18 11:04:32 +01:00
parent 2f32761681
commit 273d92bf95
9 changed files with 163 additions and 117 deletions

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\methods\\insertTicket.js"
}
]
}

View File

@ -1,28 +0,0 @@
const insertShelving = require('./methods/insertShelving');
const bindShelving = require('./methods/bindShelving');
const filter = require('./utilities/filter');
const insertDB = require('./db/insertDB')
function bindShelvingTag(barcode, shelving, level){
if(filter.isBarcode(barcode)){
if(filter.isShelving(shelving)){
let shelvingId = shelving + level;
insertShelving.insertShelving(shelvingId);
bindShelving.bindShelving(barcode, shelvingId);
insertDB.insertDB(barcode, shelving, level);
}else{
console.log("¡MATRICULA INCORRECTA!")
}
}else{
console.log("¡CODIGO DE ETIQUETA INCORRECTO!")
}
}
///DATOS INTRODUCIDOS POR EL USUARIO////
var barcode = "A0A3B8224DBF"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F)
var shelving = "ABC"; //valido = 3 CARACTERES LETRAS (A-Z)
var level = "4";
//////////////////////////////////////
bindShelvingTag(barcode, shelving, level);

View File

@ -1,24 +0,0 @@
const insert = require('./methods/insertTicket');
const filter = require('./utilities/filter');
const select = require('./db/selectDB');
const maxWagon = require('./db/maxWagon');
var barcode = "A0A3B820690F";
//var shelving = "BCD";///introducida por el usuario O en leida de la bbdd?
var collectionFk = '273449';
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)){
insert.insertTicket(data, shelving, max)
//}else{
//console.log("¡MATRICULA INCORRECTA!")
//}
});
});
}
ticketCollection(collectionFk);

View File

@ -3,7 +3,7 @@ const con = require('./connect')
function insertDB(barcode, shelving, level){
con.con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
//console.log("Connected!");
var sql = `IF EXISTS(SELECT * FROM vn.smartTag WHERE code='${barcode}')
THEN
UPDATE vn.smartTag
@ -16,7 +16,7 @@ function insertDB(barcode, shelving, level){
END IF;`;
con.con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
//console.log("1 record inserted");
});
});
}

View File

@ -1,27 +0,0 @@
const config = require('../config');
const got = require('got');
function bindShelving(barcode, shelvingId){
(async() => {
const info = await config.info
let key = info.data.token;
(async() => {
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', {
json: {
storeId: config.storeId,
tagItemBinds: [{
eslBarcode: barcode,
itemBarcode: shelvingId
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log("ETIQUETA: ",body)
})();
})();
}
exports.bindShelving = bindShelving;

100
methods/bindShelvingTag.js Normal file
View File

@ -0,0 +1,100 @@
const config = require('../config');
const got = require('got');
const filter = require('../utilities/filter');
const insertDB = require('../db/insertDB');
const express = require('express');
const router = express.Router();
router.get('/', async(req, res) => {
///DATOS INTRODUCIDOS POR EL USUARIO////
var barcode = "A0A3B8224DBF"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F)
var shelving = "ABC"; //valido = 3 CARACTERES LETRAS (A-Z)
var level = "4";
//////////////////////////////////////
const result = bindShelvingTag(barcode, shelving, level);
if(result == 'INVALID_PLATE'){
res.json({message: 'MATRICULA INCORRECTA'})
}else if (result == 'INVALID_TAG_CODE'){
res.json({message: 'CODIGO DE ETIQUETA INCORRECTO'})
}else{
res.json({message: 'SUCCESS'});
}
});
module.exports = router;
function bindShelvingTag(barcode, shelving, level){
if(filter.isBarcode(barcode)){
if(filter.isShelving(shelving)){
let shelvingId = shelving + level;
insertShelving(shelvingId);
bindShelving(barcode, shelvingId);
insertDB.insertDB(barcode, shelving, level);
}else{
//console.log("¡MATRICULA INCORRECTA!");
return 'INVALID_PLATE';
}
}else{
//console.log("¡CODIGO DE ETIQUETA INCORRECTO!")
return 'INVALID_TAG_CODE';
}
}
function insertShelving(shelvingId){
(async() => {
const info = await config.info
let key = info.data.token
let currentUser = info.data.currentUser;
(async() => {
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: "sinTicket",
barCode: shelvingId,//Matricula + nivel
itemTitle: "Etiqueta Sin ticket",
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
//console.log("CARRO: ",body)
})();
})();
}
function bindShelving(barcode, shelvingId){
(async() => {
const info = await config.info
let key = info.data.token;
(async() => {
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', {
json: {
storeId: config.storeId,
tagItemBinds: [{
eslBarcode: barcode,
itemBarcode: shelvingId
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
//console.log("ETIQUETA: ",body)
})();
})();
}
exports.bindShelving = bindShelving;

View File

@ -1,3 +1,34 @@
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!")
//}
});
});
}
function insertTicket(consultaSql, shelving, max){
const config = require('../config');
const got = require('got');
@ -32,7 +63,8 @@ function insertTicket(consultaSql, shelving, max){
"Authorization": key
}
})
console.log(body,consultaSql[i].Ticket,shelving[consultaSql[i].Wagon-1],consultaSql[i].Level.toString().charAt(j))
return true;
//console.log(body,consultaSql[i].Ticket,shelving[consultaSql[i].Wagon-1],consultaSql[i].Level.toString().charAt(j))
}
}
})();

View File

@ -1,35 +0,0 @@
const config = require('../config');
const got = require('got');
function insertShelving(shelvingId){
(async() => {
const info = await config.info
let key = info.data.token
let currentUser = info.data.currentUser;
(async() => {
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: "sinTicket",
barCode: shelvingId,//Matricula + nivel
itemTitle: "Etiqueta Sin ticket",
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log("CARRO: ",body)
})();
})();
}
exports.insertShelving = insertShelving;

11
server.js Normal file
View File

@ -0,0 +1,11 @@
const express = require('express');
const app = express();
const port = 9999;
app.use('/bindShelving', require('./methods/bindShelvingTag'));
app.use('/insertTicket', require('./methods/bindTicketShelving'));
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
});