Handle status error
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Sergio De la torre 2022-06-01 12:49:18 +02:00
parent 8b748c843e
commit cae267f012
2 changed files with 11 additions and 8 deletions

View File

@ -7,19 +7,19 @@ 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;
const shelvingId = shelving + level;
filter.isSmartTag(smartTagFk);
await filter.isShelving(shelving);
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'});
res.json({ message: 'SUCCESS' });
});
module.exports = router;

View File

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