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; const shelvingId = shelving + level; filter.isSmartTag(smartTagFk, res); await filter.isShelving(shelving, res); // Vinculamos la etiqueta con la balda del carry y en la base de datos await insertShelving(shelvingId, smartTagFk); // al carry en ESL CLOUD SYSTEM insertSmartTag(smartTagFk, shelving, level); // en vn.smartTag res.json({ message: 'SUCCESS' }); }); module.exports = router; // Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket async function insertShelving(shelvingId, smartTagFk) { const info = await dataLogIn.dataLogIn; const key = info.data.token; const currentUser = info.data.currentUser; await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line json: { agencyId: currentUser.agencyId, merchantId: currentUser.merchantId, storeId: config.storeId, unitName: currentUser.unitName, itemList: [ { attrCategory: 'verdnatura', // Plantilla attrName: 'withOutTicket', // Tipo de Plantilla barCode: shelvingId, // Matricula + nivel --> Cod.Barras artículo itemTitle: 'tagWithOutTicket', qrCode: shelvingId } ] }, responseType: 'json', headers: { 'Authorization': key } }); 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 } }); }