bot-functions 1.3.5 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +38 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -14,6 +14,7 @@ const _ = require('lodash');
14
14
  const { simpleParser } = require('mailparser');
15
15
  const xpath = require('xpath');
16
16
  const { JSDOM } = require('jsdom');
17
+ const { param } = require('../retail-analyzer-models/src/routes');
17
18
 
18
19
 
19
20
  async function obtenerCorreos(email, password, subject) {
@@ -505,6 +506,16 @@ const insertEvidence4 = async (rutaFile, rutaImg, db, idgfc, periodo, fecha, tip
505
506
  })
506
507
  }
507
508
 
509
+ // inserEvidence original, para que las evidencias se inserten por ejecucion
510
+ const insertEvidenceCore = async (rutaFile, rutaImg, db, idgfc, periodo, fecha, tipo) => {
511
+ return new Promise(async function (resolve) {
512
+ const strFile = (rutaFile != "") ? "rutaArchivo" : "rutaCaptura";
513
+ const fileInsert = (rutaFile != "") ? rutaFile : rutaImg;
514
+ await axios.post(process.env.INSERT_EVIDENCE_CORE, { db, strFile, tipo, fileInsert, idgfc, periodo, fecha });
515
+ resolve(true);
516
+ });
517
+ }
518
+
508
519
  const insertLog = async (params, codigo) => {
509
520
  return new Promise(async function (resolve) {
510
521
  try {
@@ -1147,13 +1158,11 @@ const sendFile4 = async (pathDownloads, params) => {
1147
1158
  periodo = process.env.PERIODO
1148
1159
  fecha = params.reporte.prefix;
1149
1160
  //CARGA DE EVIDENCIAS DE BOTS SEMANALES Y MENSUALES
1150
- const gfcSemanal = [82,398,49495,49845,50119,39369,50045,50124,50114,50140,50137,50141,50157,50160,50159,50169,50170,50172,50182,50191,50192,50193,50187,50203];
1151
- if(gfcSemanal.includes(params.robot.idgfc)){
1161
+ if(params.robot.base_portal == 'wm'){
1152
1162
  periodo = 0;
1153
1163
  fecha = params.reporte.interval[params.reporte.interval.length - 1];
1154
1164
  }
1155
- await insertEvidence4(uploadFileResponse.data.data, '', params.robot.baseHyperCube, params.robot.idgfc, periodo,
1156
- fecha, params.reporte.type)
1165
+ await insertEvidenceCore(uploadFileResponse.data.data, '', params.robot.baseHyperCube, params.robot.idgfc, periodo, fecha, params.reporte.type)
1157
1166
  await insertLog2(params, 305);
1158
1167
  resolve();
1159
1168
  }
@@ -1344,6 +1353,28 @@ function diferenciaHoras(tiempo1, tiempo2) {
1344
1353
  return `${horas.toString().padStart(2, "0")}:${minutos.toString().padStart(2, "0")}`;
1345
1354
  }
1346
1355
 
1356
+ const insertCatspecs = async ({ db, area, cadena, nivel, fecha, val1, val5 }) => {
1357
+ try {
1358
+ const insertCatspecsResponse = await axios.post(process.env.POST_CATSPECS, {
1359
+ db, area, cadena, nivel, fecha, val1, val5
1360
+ });
1361
+ return insertCatspecsResponse.data;
1362
+ } catch (e) {
1363
+ log.error(e.message);
1364
+ throw new Error("No se pudo insertar la información de catspecs");
1365
+ }
1366
+ }
1367
+
1368
+ const uploadImageToS3 = async (filePath, key) => {
1369
+ const fileData = fs.readFileSync(filePath);
1370
+ const regs = await axios.post(process.env.AUTH_PATH, { email: process.env.EMAIL_API });
1371
+ const body = { type: 1, bucketName: process.env.S3_BUCKET, file: fileData.toString('base64'), key };
1372
+ const uploadFileResponse = await axios.post(process.env.S3_UPLOAD_FILE, body,
1373
+ { maxBodyLength: Infinity, headers: { 'Authorization': regs.data.data, 'Content-Type': 'application/json' } }
1374
+ );
1375
+ return uploadFileResponse.data.data;
1376
+ }
1377
+
1347
1378
 
1348
1379
  module.exports = {
1349
1380
  waitNtype,
@@ -1397,5 +1428,7 @@ module.exports = {
1397
1428
  manageEmails,
1398
1429
  insertLogExec,
1399
1430
  sendDataCH,
1400
- processDataDaily
1431
+ processDataDaily,
1432
+ uploadImageToS3,
1433
+ insertCatspecs,
1401
1434
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bot-functions",
3
- "version": "1.3.5",
3
+ "version": "1.5.1",
4
4
  "description": "Bot functions",
5
5
  "main": "index.js",
6
6
  "scripts": {