From 7f5be2a5661c84459daeb956983fd603d2234a05 Mon Sep 17 00:00:00 2001 From: alexmorenograu <61759297+alexmorenograu@users.noreply.github.com> Date: Thu, 18 Mar 2021 13:56:34 +0100 Subject: [PATCH] extract logIn --- methods/bindShelvingTag.js | 9 +++++---- methods/bindTicketShelving.js | 4 ++-- methods/logIn.js | 17 +++++++++++++++++ server.js | 4 ++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 methods/logIn.js diff --git a/methods/bindShelvingTag.js b/methods/bindShelvingTag.js index d38ad9b..0e25e84 100644 --- a/methods/bindShelvingTag.js +++ b/methods/bindShelvingTag.js @@ -1,4 +1,4 @@ -const config = require('../config'); +const dataLogIn = require('../server'); const got = require('got'); const filter = require('../utilities/filter'); const insertDB = require('../db/insertDB'); @@ -38,7 +38,8 @@ function bindShelvingTag(barcode, shelving, level) { function insertShelving(shelvingId) { (async() => { - const info = await config.info; + const info = await dataLogIn.dataLogIn; + console.log(info); let key = info.data.token; let currentUser = info.data.currentUser; (async() => { @@ -68,12 +69,12 @@ function insertShelving(shelvingId) { function bindShelving(barcode, shelvingId) { (async() => { - const info = await config.info; + const info = await dataLogIn.dataLogIn; let key = info.data.token; (async() => { const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/bind/batchBind', { // eslint-disable-line json: { - storeId: config.storeId, + storeId: dataLogIn.storeId, tagItemBinds: [{ eslBarcode: barcode, itemBarcode: shelvingId diff --git a/methods/bindTicketShelving.js b/methods/bindTicketShelving.js index ecedf8a..88ab606 100644 --- a/methods/bindTicketShelving.js +++ b/methods/bindTicketShelving.js @@ -25,10 +25,10 @@ function ticketCollection(collectionFk) {// parametro collectionFk } function insertTicket(consultaSql, shelving, max) { - const config = require('../config'); + const dataLogIn = require('../server'); const got = require('got'); (async() => { - const info = await config.info; + const info = await dataLogIn.dataLogIn; let key = info.data.token; let currentUser = info.data.currentUser; diff --git a/methods/logIn.js b/methods/logIn.js new file mode 100644 index 0000000..7881a70 --- /dev/null +++ b/methods/logIn.js @@ -0,0 +1,17 @@ +const info = (async() => { + const config = require('../config'); + const encrypt = require('../utilities/encrypted'); + const got = require('got'); + + const {body} = await got.post('http://app.etiquetaselectronicas.com:9999/user/login', { + json: { + account: config.user, + loginType: 3, + password: await encrypt.encryptPassword(config.password) + }, + responseType: 'json' + }); + return body; +})(); + +exports.info = info; diff --git a/server.js b/server.js index 755c0da..fa3083b 100644 --- a/server.js +++ b/server.js @@ -1,6 +1,10 @@ const express = require('express'); const app = express(); const port = 9999; +const logIn = require('./methods/logIn'); + +const dataLogIn = logIn.info; +exports.dataLogIn = dataLogIn; app.use('/bindShelving', require('./methods/bindShelvingTag')); app.use('/insertTicket', require('./methods/bindTicketShelving'));