This repository has been archived on 2024-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
smart-tag/methods/bindShelvingTag.js

100 lines
3.7 KiB
JavaScript
Raw Normal View History

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');
const insertSmartTag = require('../db/insertSmartTag');
2021-03-18 10:04:32 +00:00
const express = require('express');
2021-03-18 10:44:14 +00:00
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)
2021-03-22 07:50:57 +00:00
const shelving = req.params.shelving;// valido = 3 CARACTERES LETRAS (A-Z)
const level = req.params.level;
console.log(smartTagFk);
2021-03-25 12:38:48 +00:00
console.log(shelving + level);
2021-03-18 10:04:32 +00:00
const result = bindShelvingTag(smartTagFk, 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;
// 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)) {
2021-03-18 10:38:05 +00:00
if (filter.isShelving(shelving)) {
insertShelving(shelvingId, smartTagFk); // al carry en ESL CLOUD SYSTEM
insertSmartTag.insertSmartTag(smartTagFk, shelving, level); // en vn.smartTag
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
// Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket
async function insertShelving(shelvingId, smartTagFk) {
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-05-13 07:20:03 +00:00
itemTitle: 'Etiqueta Sin ticket',
qrCode: shelvingId
2021-03-18 10:38:05 +00:00
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
await bindShelving(smartTagFk, shelvingId);
2021-03-25 12:38:48 +00:00
console.log('Insert Shelving:', body);
2021-03-18 10:04:32 +00:00
})();
})();
}
// Creamos la etiqueta con su vinculada con el ShelvingId al articulo
async function bindShelving(smartTagFk, 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: [{
eslBarcode: smartTagFk,
2021-03-18 10:38:05 +00:00
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;