2021-03-18 10:04:32 +00:00
|
|
|
const config = require('../config');
|
|
|
|
const got = require('got');
|
|
|
|
const filter = require('../utilities/filter');
|
|
|
|
const insertDB = require('../db/insertDB');
|
|
|
|
const express = require('express');
|
2021-03-18 10:44:14 +00:00
|
|
|
const router = express.Router(); // eslint-disable-line
|
2021-03-18 10:04:32 +00:00
|
|
|
|
|
|
|
router.get('/', async(req, res) => {
|
2021-03-18 10:38:05 +00:00
|
|
|
// DATOS INTRODUCIDOS POR EL USUARIO
|
|
|
|
let barcode = 'A0A3B8224DBF'; // valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F)
|
|
|
|
let shelving = 'ABC'; // valido = 3 CARACTERES LETRAS (A-Z)
|
|
|
|
let level = '4';
|
|
|
|
// ////////////////////////////////////
|
2021-03-18 10:04:32 +00:00
|
|
|
|
|
|
|
const result = bindShelvingTag(barcode, shelving, level);
|
2021-03-18 10:38:05 +00:00
|
|
|
if (result == 'INVALID_PLATE')
|
|
|
|
res.json({message: 'MATRICULA INCORRECTA'});
|
|
|
|
else if (result == 'INVALID_TAG_CODE')
|
|
|
|
res.json({message: 'CODIGO DE ETIQUETA INCORRECTO'});
|
|
|
|
else
|
2021-03-18 10:04:32 +00:00
|
|
|
res.json({message: 'SUCCESS'});
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|
|
|
|
|
2021-03-18 10:38:05 +00:00
|
|
|
function bindShelvingTag(barcode, shelving, level) {
|
|
|
|
if (filter.isBarcode(barcode)) {
|
|
|
|
if (filter.isShelving(shelving)) {
|
2021-03-18 10:04:32 +00:00
|
|
|
let shelvingId = shelving + level;
|
|
|
|
insertShelving(shelvingId);
|
|
|
|
bindShelving(barcode, shelvingId);
|
|
|
|
insertDB.insertDB(barcode, shelving, level);
|
2021-03-18 10:51:40 +00:00
|
|
|
} else
|
2021-03-18 10:04:32 +00:00
|
|
|
return 'INVALID_PLATE';
|
2021-03-18 10:51:40 +00:00
|
|
|
} else
|
2021-03-18 10:04:32 +00:00
|
|
|
return 'INVALID_TAG_CODE';
|
2021-03-18 10:38:05 +00:00
|
|
|
}
|
2021-03-18 10:04:32 +00:00
|
|
|
|
2021-03-18 10:38:05 +00:00
|
|
|
function insertShelving(shelvingId) {
|
2021-03-18 10:04:32 +00:00
|
|
|
(async() => {
|
2021-03-18 10:38:05 +00:00
|
|
|
const info = await config.info;
|
|
|
|
let key = info.data.token;
|
2021-03-18 10:04:32 +00:00
|
|
|
let currentUser = info.data.currentUser;
|
|
|
|
(async() => {
|
2021-03-18 10:44:14 +00:00
|
|
|
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
|
2021-03-18 10:38:05 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
2021-03-18 10:04:32 +00:00
|
|
|
})();
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2021-03-18 10:38:05 +00:00
|
|
|
function bindShelving(barcode, shelvingId) {
|
2021-03-18 10:04:32 +00:00
|
|
|
(async() => {
|
2021-03-18 10:38:05 +00:00
|
|
|
const info = await config.info;
|
2021-03-18 10:04:32 +00:00
|
|
|
let key = info.data.token;
|
|
|
|
(async() => {
|
2021-03-18 10:44:14 +00:00
|
|
|
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
|
2021-03-18 10:04:32 +00:00
|
|
|
json: {
|
|
|
|
storeId: config.storeId,
|
|
|
|
tagItemBinds: [{
|
2021-03-18 10:38:05 +00:00
|
|
|
eslBarcode: barcode,
|
|
|
|
itemBarcode: shelvingId
|
|
|
|
}
|
2021-03-18 10:04:32 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
responseType: 'json',
|
|
|
|
headers: {
|
2021-03-18 10:38:05 +00:00
|
|
|
'Authorization': key
|
2021-03-18 10:04:32 +00:00
|
|
|
}
|
2021-03-18 10:38:05 +00:00
|
|
|
});
|
2021-03-18 10:04:32 +00:00
|
|
|
})();
|
|
|
|
})();
|
|
|
|
}
|
2021-03-18 10:38:05 +00:00
|
|
|
exports.bindShelving = bindShelving;
|