refactor(errors)
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-03-31 12:51:01 +02:00
parent 4e65fb42d0
commit 278346233d
2 changed files with 12 additions and 22 deletions

View File

@ -11,31 +11,19 @@ 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 result = await bindShelvingTag(smartTagFk, shelving, level);
const shelvingId = shelving + level;
if (result == 'INVALID_PLATE')
throw new Error('CODIGO MATRICULA INCORRECTO');
else if (result == 'INVALID_TAG_CODE')
throw new Error('CODIGO DE ETIQUETA INCORRECTO');
else
res.json({message: 'SUCCESS'});
filter.isSmartTag(smartTagFk);
await filter.isShelving(shelving);
// 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;
// Vinculamos la etiqueta con la balda del carry y en la base de datos
async function bindShelvingTag(smartTagFk, shelving, level) {
let shelvingId = shelving + level;
if (filter.isSmartTag(smartTagFk)) {
if (await filter.isShelving(shelving)) {
insertShelving(shelvingId, smartTagFk); // al carry en ESL CLOUD SYSTEM
insertSmartTag(smartTagFk, shelving, level); // en vn.smartTag
} else
return 'INVALID_PLATE';
} else
return 'INVALID_TAG_CODE';
}
// Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket
async function insertShelving(shelvingId, smartTagFk) {
const info = await dataLogIn.dataLogIn;

View File

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