const config = require('../config'); const got = require('got'); const filter = require('../utilities/filter'); const insertDB = require('../db/insertDB'); const express = require('express'); const router = express.Router(); // eslint-disable-line router.get('/', async(req, res) => { // 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'; // //////////////////////////////////// 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); bindShelving(barcode, shelvingId); insertDB.insertDB(barcode, shelving, level); } else return 'INVALID_PLATE'; } else return 'INVALID_TAG_CODE'; } function insertShelving(shelvingId) { (async() => { const info = await config.info; 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 } }); })(); })(); } function bindShelving(barcode, shelvingId) { (async() => { const info = await config.info; 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 } }); })(); })(); } exports.bindShelving = bindShelving;