feat(flashOn): change options and error handling
gitea/smart-tag/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-06-03 08:54:35 +02:00
parent b113636e9c
commit e92104f55a
1 changed files with 11 additions and 5 deletions

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)
res.status(400).json({error: {code: 'flashError', message: 'Este ticket no está asociado'}});
await insertFlash(ticket);
res.json({message: 'SUCCESS'});
@ -20,17 +23,20 @@ async function insertFlash(ticket) {
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)
res.status(400).json({error: {code: 'flashError', message: response.body.message}});
}