100 lines
3.7 KiB
JavaScript
100 lines
3.7 KiB
JavaScript
const dataLogIn = require('../server');
|
|
const got = require('got');
|
|
const filter = require('../utilities/filter');
|
|
const config = require('../config');
|
|
const insertSmartTag = require('../db/insertSmartTag');
|
|
const express = require('express');
|
|
const router = express.Router(); // eslint-disable-line
|
|
|
|
// Obtenemos los parametros
|
|
router.get('/:smartTagFk&:shelving&:level', async(req, res) => {
|
|
const smartTagFk = req.params.smartTagFk;// 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(smartTagFk);
|
|
console.log(shelving + level);
|
|
|
|
const result = bindShelvingTag(smartTagFk, 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;
|
|
|
|
// Vinculamos la etiqueta con la balda del carry y en la base de datos
|
|
function bindShelvingTag(smartTagFk, shelving, level) {
|
|
let shelvingId = shelving + level;
|
|
if (filter.isSmartTag(smartTagFk)) {
|
|
if (filter.isShelving(shelving)) {
|
|
insertShelving(shelvingId, smartTagFk); // al carry en ESL CLOUD SYSTEM
|
|
insertSmartTag.insertSmartTag(smartTagFk, shelving, level); // en vn.smartTag
|
|
} else
|
|
return 'INVALID_PLATE';
|
|
} else
|
|
return 'INVALID_TAG_CODE';
|
|
}
|
|
|
|
// Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket
|
|
async function insertShelving(shelvingId, smartTagFk) {
|
|
(async() => {
|
|
const info = await dataLogIn.dataLogIn;
|
|
let key = info.data.token;
|
|
let currentUser = info.data.currentUser;
|
|
(async() => {
|
|
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
|
|
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',
|
|
qrCode: shelvingId
|
|
}
|
|
]
|
|
},
|
|
responseType: 'json',
|
|
headers: {
|
|
'Authorization': key
|
|
}
|
|
});
|
|
await bindShelving(smartTagFk, shelvingId);
|
|
console.log('Insert Shelving:', body);
|
|
})();
|
|
})();
|
|
}
|
|
|
|
// Creamos la etiqueta con su vinculada con el ShelvingId al articulo
|
|
async function bindShelving(smartTagFk, shelvingId) {
|
|
(async() => {
|
|
const info = await dataLogIn.dataLogIn;
|
|
let key = info.data.token;
|
|
(async() => {
|
|
const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
|
|
json: {
|
|
storeId: config.storeId,
|
|
tagItemBinds: [{
|
|
eslBarcode: smartTagFk,
|
|
itemBarcode: shelvingId
|
|
}
|
|
]
|
|
},
|
|
responseType: 'json',
|
|
headers: {
|
|
'Authorization': key
|
|
}
|
|
});
|
|
console.log('Bind', body);
|
|
})();
|
|
})();
|
|
}
|
|
exports.bindShelving = bindShelving;
|