From 2060cc56710288a7dfc26ec0835ec828d6c14e21 Mon Sep 17 00:00:00 2001 From: alexmorenograu <61759297+alexmorenograu@users.noreply.github.com> Date: Mon, 22 Mar 2021 09:25:09 +0100 Subject: [PATCH] filter update --- methods/bindTicketShelving.js | 11 +++++++---- utilities/filter.js | 11 ++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/methods/bindTicketShelving.js b/methods/bindTicketShelving.js index 916d405..e9ed3e5 100644 --- a/methods/bindTicketShelving.js +++ b/methods/bindTicketShelving.js @@ -2,14 +2,18 @@ const express = require('express'); const router = express.Router(); // eslint-disable-line // const filter = require('../utilities/filter'); const select = require('../db/selectDB'); +const filter = require('../utilities/filter'); router.get('/:collectionShelving&:collectionFk', async(req, res) => { const collectionShelving = req.params.collectionShelving.split(','); const collectionFk = req.params.collectionFk; console.log(collectionShelving); console.log(collectionFk); - ticketShelving(collectionShelving, collectionFk); - res.json({message: 'SUCCESS'}); + if (filter.isShelving(collectionShelving)) { + ticketShelving(collectionShelving, collectionFk); + res.json({message: 'SUCCESS'}); + } else + res.json({message: 'SHELVING ERROR'}); }); module.exports = router; @@ -34,7 +38,6 @@ function insertTicket(consultaSql, shelving) { (async() => { for (let i = 0; i < consultaSql.length; i++) { - console.log(i); for (let j = 0; j < consultaSql[i].Level.toString().length; j++) { const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line json: { @@ -59,7 +62,7 @@ function insertTicket(consultaSql, shelving) { 'Authorization': key } }); - console.log(body); + console.log(i, body); } } })(); diff --git a/utilities/filter.js b/utilities/filter.js index 0fd72c9..6bf7d28 100644 --- a/utilities/filter.js +++ b/utilities/filter.js @@ -2,9 +2,18 @@ function isBarcode(toFilter) { const exp = /^A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]$/; return exp.test(toFilter); } +let n = true; function isShelving(toFilter) { const exp = /^[A-Z][A-Z][A-Z]$/; - return exp.test(toFilter); + toFilter.forEach(element => { + let state = exp.test(element); + if (state == false) + n = false; + }); + if (n == false) + return false; + else + return true; } exports.isBarcode = isBarcode; exports.isShelving = isShelving;