2021-03-18 12:56:34 +00:00
|
|
|
const dataLogIn = require('../server');
|
2021-03-18 10:04:32 +00:00
|
|
|
const got = require('got');
|
|
|
|
const filter = require('../utilities/filter');
|
2021-03-22 10:14:33 +00:00
|
|
|
const config = require('../config');
|
2021-03-18 10:04:32 +00:00
|
|
|
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
|
|
|
|
2021-03-22 07:50:57 +00:00
|
|
|
router.get('/:barcode&:shelving&:level', async(req, res) => {
|
|
|
|
const barcode = req.params.barcode;// valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F)
|
|
|
|
const shelving = req.params.shelving;// valido = 3 CARACTERES LETRAS (A-Z)
|
|
|
|
const level = req.params.level;
|
|
|
|
console.log(barcode);
|
2021-03-25 12:38:48 +00:00
|
|
|
console.log(shelving + level);
|
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;
|
2021-03-25 12:38:48 +00:00
|
|
|
insertShelving(shelvingId, barcode);
|
2021-03-18 10:04:32 +00:00
|
|
|
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-25 12:38:48 +00:00
|
|
|
async function insertShelving(shelvingId, barcode) {
|
2021-03-18 10:04:32 +00:00
|
|
|
(async() => {
|
2021-03-18 12:56:34 +00:00
|
|
|
const info = await dataLogIn.dataLogIn;
|
2021-03-18 10:38:05 +00:00
|
|
|
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
|
2021-03-26 15:26:17 +00:00
|
|
|
itemTitle: 'Etiqueta Sin ticket'
|
2021-03-18 10:38:05 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
responseType: 'json',
|
|
|
|
headers: {
|
|
|
|
'Authorization': key
|
|
|
|
}
|
|
|
|
});
|
2021-03-25 12:38:48 +00:00
|
|
|
await bindShelving(barcode, shelvingId);
|
|
|
|
console.log('Insert Shelving:', body);
|
2021-03-18 10:04:32 +00:00
|
|
|
})();
|
|
|
|
})();
|
|
|
|
}
|
|
|
|
|
2021-03-25 12:38:48 +00:00
|
|
|
async function bindShelving(barcode, shelvingId) {
|
2021-03-18 10:04:32 +00:00
|
|
|
(async() => {
|
2021-03-18 12:56:34 +00:00
|
|
|
const info = await dataLogIn.dataLogIn;
|
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: {
|
2021-03-22 10:14:33 +00:00
|
|
|
storeId: config.storeId,
|
2021-03-18 10:04:32 +00:00
|
|
|
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-25 12:38:48 +00:00
|
|
|
console.log('Bind', body);
|
2021-03-18 10:04:32 +00:00
|
|
|
})();
|
|
|
|
})();
|
|
|
|
}
|
2021-03-18 10:38:05 +00:00
|
|
|
exports.bindShelving = bindShelving;
|