Compare commits

...
This repository has been archived on 2024-10-02. You can view files and clone it, but cannot push or open issues or pull requests.

2 Commits
test ... master

Author SHA1 Message Date
Alex Moreno 3576ff08e6 error handling
gitea/smart-tag/pipeline/head This commit looks good Details
2022-06-03 08:59:31 +02:00
Alex Moreno e92104f55a feat(flashOn): change options and error handling
gitea/smart-tag/pipeline/head This commit looks good Details
2022-06-03 08:54:35 +02:00
4 changed files with 18 additions and 12 deletions

View File

@ -25,7 +25,7 @@ router.get('/:smartTagFk&:shelving&:level', async(req, res) => {
module.exports = router;
// Creamos un "articulo", que sera el que luego modificaremos para añadirle un ticket
async function insertShelving(shelvingId, smartTagFk) {
async function insertShelving(shelvingId, smartTagFk, res) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
const currentUser = info.data.currentUser;
@ -52,7 +52,7 @@ async function insertShelving(shelvingId, smartTagFk) {
}
});
if (!response.body.success)
res.status(400).json({error: {code: 'bindingCreateError', message: response.body.message}});
return 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: {
@ -69,5 +69,5 @@ async function insertShelving(shelvingId, smartTagFk) {
}
});
if (!response.body.success)
res.status(400).json({error: {code: 'bindingTagError', message: response.body.message}});
return res.status(400).json({error: {code: 'bindingTagError', message: response.body.message}});
}

View File

@ -10,7 +10,7 @@ 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'}});
return res.status(400).json({error: {code: 'emptyCollectionSmartTag', message: 'No hay datos'}});
await insertTicket(collection);

View File

@ -8,7 +8,10 @@ const got = require('got');
router.get('/:ticket', async(req, res) => {
const ticketId = req.params.ticket;
const ticket = selectTicket(ticketId);
const [ticket] = await selectTicket(ticketId);
if (!ticket.length)
return res.status(400).json({error: {code: 'flashError', message: 'Este ticket no está asociado'}});
await insertFlash(ticket);
res.json({message: 'SUCCESS'});
@ -16,21 +19,24 @@ router.get('/:ticket', async(req, res) => {
module.exports = router;
async function insertFlash(ticket) {
async function insertFlash(ticket, res) {
const info = await dataLogIn.dataLogIn;
const key = info.data.token;
await got.post('http://app.etiquetaselectronicas.com:9999/led/excuteLed', { // eslint-disable-line
const response = await got.post('http://app.etiquetaselectronicas.com:9999/led/excuteLed', { // eslint-disable-line
json: {
storeId: config.storeId,
lightCololr: 8,
lightTime: 30,
lightCololr: 2,
lightTime: 10,
targetExecution: ticket[0].shelvingFk + ticket[0].level + '/tagWithTicket',
lightFrequency: 1
brightness: 80,
lightFrequency: 2
},
responseType: 'json',
headers: {
'Authorization': key
}
});
if (!response.body.success)
return res.status(400).json({error: {code: 'flashError', message: response.body.message}});
}

View File

@ -2,14 +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'}});
return 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'}});
return res.status(400).json({error: {code: 'invalidPlate', message: 'Matricula incorrecta'}});
}
exports.isSmartTag = isSmartTag;