Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/smart-tag into test
gitea/smart-tag/pipeline/head This commit looks good
Details
gitea/smart-tag/pipeline/head This commit looks good
Details
This commit is contained in:
commit
cf4ca514a4
|
@ -13,8 +13,8 @@ router.get('/:smartTagFk&:shelving&:level', async(req, res) => {
|
|||
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
|
||||
|
@ -30,7 +30,7 @@ async function insertShelving(shelvingId, smartTagFk) {
|
|||
const key = info.data.token;
|
||||
const currentUser = info.data.currentUser;
|
||||
|
||||
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
|
||||
let response = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
|
||||
json: {
|
||||
agencyId: currentUser.agencyId,
|
||||
merchantId: currentUser.merchantId,
|
||||
|
@ -51,7 +51,10 @@ async function insertShelving(shelvingId, smartTagFk) {
|
|||
'Authorization': key
|
||||
}
|
||||
});
|
||||
await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line
|
||||
if (!response.body.success)
|
||||
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: {
|
||||
storeId: config.storeId,
|
||||
tagItemBinds: [{
|
||||
|
@ -65,4 +68,6 @@ async function insertShelving(shelvingId, smartTagFk) {
|
|||
'Authorization': key
|
||||
}
|
||||
});
|
||||
if (!response.body.success)
|
||||
res.status(400).json({error: {code: 'bindingTagError', message: response.body.message}});
|
||||
}
|
||||
|
|
|
@ -3,12 +3,17 @@ const router = express.Router(); // eslint-disable-line
|
|||
const collectionSmartTag = require('../db/selectCollection');
|
||||
const dataLogIn = require('../server');
|
||||
const got = require('got');
|
||||
const config = require('../config');
|
||||
// const insertTicketDB = require('../db/insertTicket');
|
||||
|
||||
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'}});
|
||||
|
||||
await insertTicket(collection);
|
||||
|
||||
res.json({message: 'SUCCESS'});
|
||||
});
|
||||
|
||||
|
@ -18,12 +23,13 @@ async function insertTicket(collection) {
|
|||
const info = await dataLogIn.dataLogIn;
|
||||
const key = info.data.token;
|
||||
const currentUser = info.data.currentUser;
|
||||
|
||||
for (let i = 0; i < collection.length; i++) {
|
||||
await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', { // eslint-disable-line
|
||||
json: {
|
||||
agencyId: currentUser.agencyId,
|
||||
merchantId: currentUser.merchantId,
|
||||
storeId: currentUser.storeId,
|
||||
storeId: config.storeId,
|
||||
unitName: currentUser.unitName,
|
||||
itemList: [
|
||||
{
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
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;
|
||||
|
|
Reference in New Issue