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

97 lines
3.3 KiB
JavaScript

const dataLogIn = require('../server');
const got = require('got');
const filter = require('../utilities/filter');
const config = require('../config');
const insertDB = require('../db/insertDB');
const express = require('express');
const router = express.Router(); // eslint-disable-line
// canviar barcode per smarttagFk
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);
console.log(shelving + level);
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, barcode);
insertDB.insertDB(barcode, shelving, level);
} else
return 'INVALID_PLATE';
} else
return 'INVALID_TAG_CODE';
}
async function insertShelving(shelvingId, barcode) {
(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'
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
await bindShelving(barcode, shelvingId);
console.log('Insert Shelving:', body);
})();
})();
}
async function bindShelving(barcode, 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: barcode,
itemBarcode: shelvingId
}
]
},
responseType: 'json',
headers: {
'Authorization': key
}
});
console.log('Bind', body);
})();
})();
}
exports.bindShelving = bindShelving;
// uihasdc