100 lines
3.3 KiB
JavaScript
100 lines
3.3 KiB
JavaScript
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; |