first commit

This commit is contained in:
alexmorenograu 2021-03-11 15:41:03 +01:00
parent 12b3da8efd
commit e39c69a35a
7 changed files with 226 additions and 59 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
config.js
node_modules
node_modules
proba.js

50
bindShelving.js Normal file
View File

@ -0,0 +1,50 @@
const insert = require('./utilities/inserts');
function smartTag(barcode, shelving, level){
const got = require('got');
const config = require('./config');
(async() => {
insert.insertShelving(shelving, level);
(async() => {
const info = await config.info
let key = info.data.token;
(async() => {
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', {
json: {
storeId: config.storeId,
tagItemBinds: [{
eslBarcode: barcode,
itemBarcode: shelving + level
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log(body)
})();
})();
})();
}
///DATOS INTRODUCIDOS POR EL USUARIO////
var barcode = "A0A3B820690F"; //valido = "A0A3B82"+ 4 CARACTERES HEXADECIMALES (0-F)
var shelving = "BCD"; //valido = 3 CARACTERES LETRAS (A-Z)
var level = "1";
//////////////////////////////////////
if(insert.filter(barcode,"barcode")){
if(insert.filter(shelving,"shelving")){
smartTag(barcode, shelving, level);
}
else{
console.log("¡MATRICULA INCORRECTA!")
}
}
else{
console.log("¡CODIGO DE ETIQUETA INCORRECTO!")
}

46
bindTicketShelving.js Normal file
View File

@ -0,0 +1,46 @@
const insert = require('./utilities/inserts');
var barcode = "A0A3B820690F";
var shelving = "ABC";///introducida por el usuario
var collectionFk = '254';
var consultaSql1 = [
{
id: 1025963,
ticketFk: 2516988,
level: 1,//en un futur no estaran
wagon: 0,//en un futur no estaran
nickname: 'FLORA&CO',
agencyModeFk: 'MRW',//Seria un numero
},
{
id: 1025964,
ticketFk: 2542131,
level: 2,
wagon: 0,
nickname: 'MORRIS',
agencyModeFk: 'MRW'//Seria un numero
},
{
id: 1025965,
ticketFk: 2542131,
level: 3,
wagon: 0,
nickname: 'MORRIS2',
agencyModeFk: 'MRW'
}
]
function ticketCollection(){//parametro collectionFk
/// CONSULTA SQL PER A TINDRE ELS DIFERENTS ticketsColletion DE UN colletionFK (consiltaSql1) ///
/// CONSULTA SQL PER A CADA ticket DE CADA ticketCollection (consiltaSql2) ///
if(insert.filter(shelving,"shelving")){
insert.insertTicket(consultaSql1, shelving)
}
else{
console.log("¡MATRICULA INCORRECTA!")
}
}
ticketCollection();

12
filter.js Normal file
View File

@ -0,0 +1,12 @@
function filter(toFilter, type){
let exp;
if(type=="barcode"){
exp = /^A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]$/
}
if(type=="shelving"){
exp = /^[A-Z][A-Z][A-Z]$/
}
return exp.test(toFilter)
}
console.log(filter("A0A3B820690FF", "barcode"))

View File

@ -1,5 +1,5 @@
const config = require('./config');
const got = require('got');
const insertJson = require('./sqlToInsert');
var barcode = "A0A3B820690F";
var shelving = "ABC";
@ -9,78 +9,33 @@ var consultaSql1 = [
{
id: 1025963,
ticketFk: 2516988,
level: 3,
wagon: 0,
},
{
id: 1025964,
ticketFk: 2542131,
level: 4,
wagon: 0
},
{
id: 1025965,
ticketFk: 2542131,
level: 5,
wagon: 0
}
]
var consultaSql2 = [
{
id: 1025963,
level: 1,//en un futur no estaran
wagon: 0,//en un futur no estaran
nickname: 'FLORA&CO',
agencyModeFk: 'MRW'//Seria un numero
agencyModeFk: 'MRW',//Seria un numero
},
{
id: 1025964,
ticketFk: 2542131,
level: 2,
wagon: 0,
nickname: 'MORRIS',
agencyModeFk: 'MRW'//Seria un numero
},
{
id: 1025965,
ticketFk: 2542131,
level: 3,
wagon: 0,
nickname: 'MORRIS2',
agencyModeFk: 'MRW'//Seria un numero
agencyModeFk: 'MRW'
}
]
function ticketCollection(){//parametro collectionFk
/// CONSULTA SQL PER A TINDRE ELS DIFERENTS ticketsColletion DE UN colletionFK (consiltaSql1) ///
/// CONSULTA SQL PER A CADA ticket DE CADA ticketCollection (consiltaSql2) ///
(async() => {
const info = await config.info
let key = info.data.token
let currentUser = info.data.currentUser;
(async() => {
for(var i=0;i<consultaSql1.length;i++){
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', {
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: "verdnatura",
attrName: "conTicket",
barCode: shelving + consultaSql1[i].level,
itemTitle: "Etiqueta Con ticket",
productCode: shelving + consultaSql1[i].level,
custFeature1: consultaSql2[i].nickname,
custFeature2: consultaSql2[i].agencyModeFk,
custFeature3: consultaSql1[i].ticketFk
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log(body)
}
})();
})();
insertJson.insertJson(consultaSql1, shelving)
}
ticketCollection();

17
utilities/encrypted.js Normal file
View File

@ -0,0 +1,17 @@
const crypto = require('crypto');
const got = require('got');
const config = require('./config');
const encryptPassword = async(password) => {
const { body } = await got.get('http://app.etiquetaselectronicas.com:9999/user/getErpPublicKey', {
});
const publicKey=`-----BEGIN PUBLIC KEY-----\n${JSON.parse(body).data}\n-----END PUBLIC KEY-----`;
const externKey = {
key: publicKey,
padding: crypto.constants.RSA_PKCS1_PADDING
};
let buffer = Buffer.from(password);
return crypto.publicEncrypt(externKey, buffer).toString("base64");
};
exports.encryptPassword = encryptPassword;

86
utilities/inserts.js Normal file
View File

@ -0,0 +1,86 @@
function insertTicket(sql, shelving){
const config = require('../config');
const got = require('got');
(async() => {
const info = await config.info
let key = info.data.token
let currentUser = info.data.currentUser;
(async() => {
for(var i=0;i<sql.length;i++){
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', {
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: "verdnatura",
attrName: "conTicket",
barCode: shelving + sql[i].level,//Matricula + nivel
itemTitle: "Etiqueta Con ticket",
productCode: sql[i].ticketFk, //Ticket
custFeature1: sql[i].nickname, //Client
custFeature2: sql[i].agencyModeFk //Agencia de transporte
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log(body)
}
})();
})();
}
function insertShelving(shelving, level){
const config = require('../config');
const got = require('got');
(async() => {
const info = await config.info
let key = info.data.token
let currentUser = info.data.currentUser;
(async() => {
const { body } = await got.post('http://app.etiquetaselectronicas.com:9999/item/batchImportItem', {
json: {
agencyId: currentUser.agencyId,
merchantId: currentUser.merchantId,
storeId: currentUser.storeId,
unitName: currentUser.unitName,
itemList: [
{
attrCategory: "verdnatura",
attrName: "sinTicket",
barCode: shelving + level,//Matricula + nivel
itemTitle: "Etiqueta Sin ticket",
}
]
},
responseType: 'json',
headers: {
"Authorization": key
}
})
console.log(body)
})();
})();
}
function filter(toFilter, type){
if(type=="barcode"){
exp = /A0A3B82[A-F0-9][A-F0-9][A-F0-9][A-F0-9][A-F0-9]/
}
if(type=="shelving"){
exp = /[A-F][A-F][A-F]/
}
return exp.test(toFilter)
}
exports.insertTicket = insertTicket;
exports.insertShelving = insertShelving;
exports.filter = filter;