fix storeId error and more error handling
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-06-02 13:59:14 +02:00
parent cae267f012
commit b113636e9c
3 changed files with 18 additions and 10 deletions

View File

@ -7,7 +7,7 @@ const express = require('express');
const router = express.Router(); // eslint-disable-line
// Obtenemos los parametros
router.get('/:smartTagFk&:shelving&:level', async (req, res) => {
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;
@ -19,7 +19,7 @@ router.get('/:smartTagFk&:shelving&:level', async (req, 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' });
res.json({message: 'SUCCESS'});
});
module.exports = router;
@ -30,7 +30,7 @@ async function insertShelving(shelvingId, smartTagFk) {
const key = info.data.token;
const currentUser = info.data.currentUser;
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
let response = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
@ -51,7 +51,10 @@ async function insertShelving(shelvingId, smartTagFk) {
'Authorization': key
}
});
await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
if (!response.body.success)
res.status(400).json({error: {code: 'bindingCreateError', message: response.body.message}});
response = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
json: {
storeId: config.storeId,
tagItemBinds: [{
@ -65,4 +68,6 @@ async function insertShelving(shelvingId, smartTagFk) {
'Authorization': key
}
});
if (!response.body.success)
res.status(400).json({error: {code: 'bindingTagError', message: response.body.message}});
}

View File

@ -3,12 +3,17 @@ const router = express.Router(); // eslint-disable-line
const collectionSmartTag = require('../db/selectCollection');
const dataLogIn = require('../server');
const got = require('got');
const config = require('../config');
// const insertTicketDB = require('../db/insertTicket');
router.get('/:collectionFk', async(req, res) => {
const collectionFk = req.params.collectionFk;
const [collection] = await collectionSmartTag(collectionFk);
if (!collection.length)
res.status(400).json({error: {code: 'emptyCollectionSmartTag', message: 'No hay datos'}});
await insertTicket(collection);
res.json({message: 'SUCCESS'});
});
@ -18,12 +23,13 @@ async function insertTicket(collection) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
for (let i = 0; i < collection.length; i++) {
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
storeId: config.storeId,
unitName: currentUser.unitName,
itemList: [
{

View File

@ -2,17 +2,14 @@ const con = require('../db/connect');
function isSmartTag(toFilter, res) {
const exp = /^A0A3B82[A-F0-9]{5}$/;
if (!exp.test(toFilter))
res.status(400).json({ error: { code: 'invalidPlate', message: 'Matricula incorrecta' } })
res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
}
async function isShelving(shelving, res) {
const sql = `SELECT * FROM vn.shelving WHERE code = ?`;
const [response] = await con.query(sql, shelving);
if (response.length == 0)
res.status(400).json({ error: { code: 'invalidPlate', message: 'Matricula incorrecta' } })
res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
}
exports.isSmartTag = isSmartTag;