hnt_jira_report 0.0.2 → 0.0.4

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.
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.outputFormatConcluido = exports.outputFormatAguardandoAprovacao = void 0;
7
+ var outputFormatAguardandoAprovacao = exports.outputFormatAguardandoAprovacao = function outputFormatAguardandoAprovacao(_ref) {
8
+ var key = _ref.key,
9
+ nro_documento_pedido = _ref.nro_documento_pedido,
10
+ nro_nota_fiscal = _ref.nro_nota_fiscal,
11
+ valor_nota = _ref.valor_nota,
12
+ razao_fornecedor = _ref.razao_fornecedor,
13
+ data_emissao = _ref.data_emissao,
14
+ data_vencimento = _ref.data_vencimento,
15
+ status = _ref.status,
16
+ grupo_compradores_denominacao = _ref.grupo_compradores_denominacao,
17
+ responsavel = _ref.responsavel,
18
+ responsavel_email = _ref.responsavel_email,
19
+ last_update = _ref.last_update;
20
+ return {
21
+ key: key,
22
+ nro_documento_pedido: nro_documento_pedido,
23
+ nro_nota_fiscal: nro_nota_fiscal,
24
+ valor_nota: valor_nota,
25
+ razao_fornecedor: razao_fornecedor,
26
+ data_emissao: data_emissao,
27
+ data_vencimento: data_vencimento,
28
+ status: status,
29
+ grupo_compradores_denominacao: grupo_compradores_denominacao,
30
+ responsavel: responsavel,
31
+ responsavel_email: responsavel_email,
32
+ last_update: last_update
33
+ };
34
+ };
35
+ var outputFormatConcluido = exports.outputFormatConcluido = function outputFormatConcluido(_ref2) {
36
+ var key = _ref2.key,
37
+ last_update = _ref2.last_update,
38
+ nro_documento_pedido = _ref2.nro_documento_pedido,
39
+ nro_nota_fiscal = _ref2.nro_nota_fiscal,
40
+ valor_nota = _ref2.valor_nota,
41
+ razao_fornecedor = _ref2.razao_fornecedor,
42
+ data_emissao = _ref2.data_emissao,
43
+ data_emissao_ano = _ref2.data_emissao_ano,
44
+ data_emissao_mes = _ref2.data_emissao_mes,
45
+ data_emissao_month = _ref2.data_emissao_month,
46
+ data_vencimento = _ref2.data_vencimento,
47
+ status = _ref2.status,
48
+ status_category_change_epoch = _ref2.status_category_change_epoch,
49
+ grupo_compradores_denominacao = _ref2.grupo_compradores_denominacao;
50
+ return {
51
+ key: key,
52
+ last_update: last_update,
53
+ nro_documento_pedido: nro_documento_pedido,
54
+ nro_nota_fiscal: nro_nota_fiscal,
55
+ valor_nota: valor_nota,
56
+ razao_fornecedor: razao_fornecedor,
57
+ data_emissao: data_emissao,
58
+ data_emissao_ano: data_emissao_ano,
59
+ data_emissao_mes: data_emissao_mes,
60
+ data_emissao_month: data_emissao_month,
61
+ data_vencimento: data_vencimento,
62
+ status: status,
63
+ status_category_change_epoch: status_category_change_epoch,
64
+ grupo_compradores_denominacao: grupo_compradores_denominacao
65
+ };
66
+ };
package/lib/bi_service.js CHANGED
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.publishReport = exports.formatReport = void 0;
6
+ exports.publishReport = exports.publishIncrementalReport = exports.formatReport = void 0;
7
7
  var _datasets_service = require("./bi/datasets_service.js");
8
8
  var _token_service = require("./bi/token_service.js");
9
+ var _format_data = require("./bi/format_data.js");
9
10
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
11
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
11
12
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -15,37 +16,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
15
16
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
16
17
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
17
18
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
- var outputFormatAguardandoAprovacao = function outputFormatAguardandoAprovacao(_ref) {
19
- var key = _ref.key,
20
- nro_documento_pedido = _ref.nro_documento_pedido,
21
- nro_nota_fiscal = _ref.nro_nota_fiscal,
22
- valor_nota = _ref.valor_nota,
23
- razao_fornecedor = _ref.razao_fornecedor,
24
- data_emissao = _ref.data_emissao,
25
- data_vencimento = _ref.data_vencimento,
26
- status = _ref.status,
27
- grupo_compradores_denominacao = _ref.grupo_compradores_denominacao,
28
- responsavel = _ref.responsavel,
29
- responsavel_email = _ref.responsavel_email,
30
- last_update = _ref.last_update;
31
- return {
32
- key: key,
33
- nro_documento_pedido: nro_documento_pedido,
34
- nro_nota_fiscal: nro_nota_fiscal,
35
- valor_nota: valor_nota,
36
- razao_fornecedor: razao_fornecedor,
37
- data_emissao: data_emissao,
38
- data_vencimento: data_vencimento,
39
- status: status,
40
- grupo_compradores_denominacao: grupo_compradores_denominacao,
41
- responsavel: responsavel,
42
- responsavel_email: responsavel_email,
43
- last_update: last_update
44
- };
45
- };
46
- var formatReport = exports.formatReport = function formatReport(_ref2) {
47
- var blockedIssues = _ref2.blockedIssues,
48
- aguardandoAprovacaoSAPIssues = _ref2.aguardandoAprovacaoSAPIssues;
19
+ var formatReport = exports.formatReport = function formatReport(_ref) {
20
+ var blockedIssues = _ref.blockedIssues,
21
+ aguardandoAprovacaoSAPIssues = _ref.aguardandoAprovacaoSAPIssues;
49
22
  var currentIsues = blockedIssues.filter(function (blockedIssue) {
50
23
  return aguardandoAprovacaoSAPIssues.find(function (i) {
51
24
  return i.key == blockedIssue.key;
@@ -56,21 +29,53 @@ var formatReport = exports.formatReport = function formatReport(_ref2) {
56
29
  return _objectSpread(_objectSpread({}, aguardandoAprovacaoSAPIssues.find(function (i) {
57
30
  return i.key == blockedIssue.key;
58
31
  })), blockedIssue);
59
- }).map(outputFormatAguardandoAprovacao);
32
+ }).map(_format_data.outputFormatAguardandoAprovacao);
60
33
  };
61
- var publishReport = exports.publishReport = /*#__PURE__*/function () {
62
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
34
+ var publishIncrementalReport = exports.publishIncrementalReport = /*#__PURE__*/function () {
35
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
63
36
  var credentials, datasetId, groupId, tableName, rows, _yield$getAccessToken, access_token;
64
37
  return _regeneratorRuntime().wrap(function _callee$(_context) {
65
38
  while (1) switch (_context.prev = _context.next) {
66
39
  case 0:
67
- credentials = _ref3.credentials, datasetId = _ref3.datasetId, groupId = _ref3.groupId, tableName = _ref3.tableName, rows = _ref3.rows;
40
+ credentials = _ref2.credentials, datasetId = _ref2.datasetId, groupId = _ref2.groupId, tableName = _ref2.tableName, rows = _ref2.rows;
68
41
  _context.next = 3;
69
42
  return (0, _token_service.getAccessToken)(credentials);
70
43
  case 3:
71
44
  _yield$getAccessToken = _context.sent;
72
45
  access_token = _yield$getAccessToken.access_token;
73
46
  _context.next = 7;
47
+ return (0, _datasets_service.postRowsInGroup)({
48
+ token: access_token,
49
+ datasetId: datasetId,
50
+ groupId: groupId,
51
+ tableName: tableName,
52
+ data: {
53
+ rows: rows
54
+ }
55
+ });
56
+ case 7:
57
+ case "end":
58
+ return _context.stop();
59
+ }
60
+ }, _callee);
61
+ }));
62
+ return function publishIncrementalReport(_x) {
63
+ return _ref3.apply(this, arguments);
64
+ };
65
+ }();
66
+ var publishReport = exports.publishReport = /*#__PURE__*/function () {
67
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
68
+ var credentials, datasetId, groupId, tableName, rows, _yield$getAccessToken2, access_token;
69
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
70
+ while (1) switch (_context2.prev = _context2.next) {
71
+ case 0:
72
+ credentials = _ref4.credentials, datasetId = _ref4.datasetId, groupId = _ref4.groupId, tableName = _ref4.tableName, rows = _ref4.rows;
73
+ _context2.next = 3;
74
+ return (0, _token_service.getAccessToken)(credentials);
75
+ case 3:
76
+ _yield$getAccessToken2 = _context2.sent;
77
+ access_token = _yield$getAccessToken2.access_token;
78
+ _context2.next = 7;
74
79
  return (0, _datasets_service.deleteRowsInGroup)({
75
80
  token: access_token,
76
81
  datasetId: datasetId,
@@ -78,7 +83,7 @@ var publishReport = exports.publishReport = /*#__PURE__*/function () {
78
83
  tableName: tableName
79
84
  });
80
85
  case 7:
81
- _context.next = 9;
86
+ _context2.next = 9;
82
87
  return (0, _datasets_service.postRowsInGroup)({
83
88
  token: access_token,
84
89
  datasetId: datasetId,
@@ -90,11 +95,11 @@ var publishReport = exports.publishReport = /*#__PURE__*/function () {
90
95
  });
91
96
  case 9:
92
97
  case "end":
93
- return _context.stop();
98
+ return _context2.stop();
94
99
  }
95
- }, _callee);
100
+ }, _callee2);
96
101
  }));
97
- return function publishReport(_x) {
98
- return _ref4.apply(this, arguments);
102
+ return function publishReport(_x2) {
103
+ return _ref5.apply(this, arguments);
99
104
  };
100
105
  }();
package/lib/index.js CHANGED
@@ -25,7 +25,22 @@ var onPublishAguardandoAprovacaoSAP = function onPublishAguardandoAprovacaoSAP(_
25
25
  jql: jql
26
26
  });
27
27
  };
28
+ var onPublishConcluido = function onPublishConcluido(_ref2) {
29
+ var credentials = _ref2.credentials,
30
+ datasetId = _ref2.datasetId,
31
+ groupId = _ref2.groupId,
32
+ tableName = _ref2.tableName,
33
+ issueKey = _ref2.issueKey;
34
+ return (0, _report_service.publishConcluido)({
35
+ credentials: credentials,
36
+ datasetId: datasetId,
37
+ groupId: groupId,
38
+ tableName: tableName,
39
+ issueKey: issueKey
40
+ });
41
+ };
28
42
  var _default = exports["default"] = {
29
43
  version: version,
30
- onPublishAguardandoAprovacaoSAP: onPublishAguardandoAprovacaoSAP
44
+ onPublishAguardandoAprovacaoSAP: onPublishAguardandoAprovacaoSAP,
45
+ onPublishConcluido: onPublishConcluido
31
46
  };
@@ -7,22 +7,25 @@ exports.getFormSimplifiedAnswers = exports.getFormIndex = void 0;
7
7
  var _axios = _interopRequireDefault(require("axios"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
9
  var cloudId = '52093aee-2a2e-452d-8cf5-603245a0d261';
10
- var instance = function instance() {
10
+ var instance = function instance(token) {
11
11
  return _axios["default"].create({
12
12
  baseURL: "https://api.atlassian.com/jira/forms/cloud/".concat(cloudId),
13
13
  headers: {
14
14
  'X-ExperimentalApi': 'opt-in',
15
- authorization: "Basic ".concat(process.env.JIRA_ACCESS_TOKEN),
15
+ authorization: "Basic ".concat(token),
16
16
  Accept: 'application/json',
17
17
  'Content-Type': 'application/json'
18
18
  }
19
19
  });
20
20
  };
21
- var getFormIndex = exports.getFormIndex = function getFormIndex(issueKey) {
22
- return instance().get("/issue/".concat(issueKey, "/form"));
21
+ var getFormIndex = exports.getFormIndex = function getFormIndex(_ref) {
22
+ var token = _ref.token,
23
+ issueKey = _ref.issueKey;
24
+ return instance(token).get("/issue/".concat(issueKey, "/form"));
23
25
  };
24
- var getFormSimplifiedAnswers = exports.getFormSimplifiedAnswers = function getFormSimplifiedAnswers(_ref) {
25
- var issueKey = _ref.issueKey,
26
- formId = _ref.formId;
27
- return instance().get("/issue/".concat(issueKey, "/form/").concat(formId, "/format/answers"));
26
+ var getFormSimplifiedAnswers = exports.getFormSimplifiedAnswers = function getFormSimplifiedAnswers(_ref2) {
27
+ var token = _ref2.token,
28
+ issueKey = _ref2.issueKey,
29
+ formId = _ref2.formId;
30
+ return instance(token).get("/issue/".concat(issueKey, "/form/").concat(formId, "/format/answers"));
28
31
  };
@@ -4,51 +4,103 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.publishAguardandoAprovacaoSAP = void 0;
7
+ exports.publishConcluido = exports.publishAguardandoAprovacaoSAP = void 0;
8
8
  var _governanca_hnt_servicos = require("./domains/governanca_hnt_servicos.js");
9
9
  var _bi_service = require("./bi_service.js");
10
+ var _format_data = require("./bi/format_data.js");
10
11
  var _issues_service = require("./issues_service.js");
11
12
  var _servicos_service = require("./servicos_service.js");
12
13
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
13
14
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
14
15
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
15
- var publishAguardandoAprovacaoSAP = exports.publishAguardandoAprovacaoSAP = /*#__PURE__*/function () {
16
+ var publishConcluido = exports.publishConcluido = /*#__PURE__*/function () {
16
17
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
17
- var credentials, datasetId, groupId, tableName, blockedIssues, _ref$jql, jql, token, power_bi, _schemaServico, fields, issues, complementIssues, rows;
18
+ var credentials, datasetId, groupId, tableName, issueKey, token, power_bi, jql, _schemaServico, fields, table_name, issues, complementIssues, rows;
18
19
  return _regeneratorRuntime().wrap(function _callee$(_context) {
19
20
  while (1) switch (_context.prev = _context.next) {
20
21
  case 0:
21
- credentials = _ref.credentials, datasetId = _ref.datasetId, groupId = _ref.groupId, tableName = _ref.tableName, blockedIssues = _ref.blockedIssues, _ref$jql = _ref.jql, jql = _ref$jql === void 0 ? null : _ref$jql;
22
+ credentials = _ref.credentials, datasetId = _ref.datasetId, groupId = _ref.groupId, tableName = _ref.tableName, issueKey = _ref.issueKey;
23
+ console.log("enter publishConcluido, issueKey:".concat(issueKey));
24
+ token = credentials.jira_access_token, power_bi = credentials.power_bi;
25
+ jql = "\"Request Type\" = \"Aprova\xE7\xF5es NFs - Servi\xE7o (GHN)\" and key = ".concat(issueKey, " and status = Conclu\xEDdo ORDER BY created DESC");
26
+ _schemaServico = (0, _governanca_hnt_servicos.schemaServico)(), fields = _schemaServico.fields, table_name = _schemaServico.db.table_name;
27
+ _context.next = 7;
28
+ return (0, _issues_service.readIssues)({
29
+ token: token,
30
+ jql: jql,
31
+ fields: fields
32
+ });
33
+ case 7:
34
+ issues = _context.sent;
35
+ _context.next = 10;
36
+ return (0, _servicos_service.enrichComplement)({
37
+ token: token,
38
+ issues: issues
39
+ });
40
+ case 10:
41
+ complementIssues = _context.sent;
42
+ rows = complementIssues.map(_format_data.outputFormatConcluido);
43
+ _context.next = 14;
44
+ return (0, _bi_service.publishIncrementalReport)({
45
+ credentials: power_bi,
46
+ datasetId: datasetId,
47
+ groupId: groupId,
48
+ tableName: tableName,
49
+ rows: rows
50
+ });
51
+ case 14:
52
+ console.log("leave publishConcluido, rows size:".concat(rows.length));
53
+ return _context.abrupt("return", rows);
54
+ case 16:
55
+ case "end":
56
+ return _context.stop();
57
+ }
58
+ }, _callee);
59
+ }));
60
+ return function publishConcluido(_x) {
61
+ return _ref2.apply(this, arguments);
62
+ };
63
+ }();
64
+ var publishAguardandoAprovacaoSAP = exports.publishAguardandoAprovacaoSAP = /*#__PURE__*/function () {
65
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
66
+ var credentials, datasetId, groupId, tableName, blockedIssues, _ref3$jql, jql, token, power_bi, _schemaServico2, fields, issues, complementIssues, rows;
67
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
68
+ while (1) switch (_context2.prev = _context2.next) {
69
+ case 0:
70
+ credentials = _ref3.credentials, datasetId = _ref3.datasetId, groupId = _ref3.groupId, tableName = _ref3.tableName, blockedIssues = _ref3.blockedIssues, _ref3$jql = _ref3.jql, jql = _ref3$jql === void 0 ? null : _ref3$jql;
22
71
  console.log("enter publishAguardandoAprovacaoSAP, blockedIssues size:".concat(blockedIssues.length));
23
72
  if (blockedIssues.length) {
24
- _context.next = 5;
73
+ _context2.next = 5;
25
74
  break;
26
75
  }
27
76
  console.log('blockedIssues is empty!');
28
- return _context.abrupt("return");
77
+ return _context2.abrupt("return");
29
78
  case 5:
30
79
  console.log('query: %s', query(jql));
31
80
  token = credentials.jira_access_token, power_bi = credentials.power_bi;
32
- _schemaServico = (0, _governanca_hnt_servicos.schemaServico)(), fields = _schemaServico.fields;
33
- _context.next = 10;
81
+ _schemaServico2 = (0, _governanca_hnt_servicos.schemaServico)(), fields = _schemaServico2.fields;
82
+ _context2.next = 10;
34
83
  return (0, _issues_service.readIssues)({
35
84
  token: token,
36
85
  jql: query(jql),
37
86
  fields: fields
38
87
  });
39
88
  case 10:
40
- issues = _context.sent;
41
- _context.next = 13;
89
+ issues = _context2.sent;
90
+ _context2.next = 13;
42
91
  return (0, _servicos_service.enrichComplement)({
92
+ token: token,
43
93
  issues: issues
44
94
  });
45
95
  case 13:
46
- complementIssues = _context.sent;
96
+ complementIssues = _context2.sent;
97
+ console.log("publishAguardandoAprovacaoSAP, complementIssues size:".concat(complementIssues.length));
47
98
  rows = (0, _bi_service.formatReport)({
48
99
  blockedIssues: blockedIssues,
49
100
  aguardandoAprovacaoSAPIssues: complementIssues
50
101
  });
51
- _context.next = 17;
102
+ console.log("publishAguardandoAprovacaoSAP, formatReport rows size:".concat(rows.length));
103
+ _context2.next = 19;
52
104
  return (0, _bi_service.publishReport)({
53
105
  credentials: power_bi,
54
106
  datasetId: datasetId,
@@ -56,16 +108,17 @@ var publishAguardandoAprovacaoSAP = exports.publishAguardandoAprovacaoSAP = /*#_
56
108
  tableName: tableName,
57
109
  rows: rows
58
110
  });
59
- case 17:
60
- return _context.abrupt("return", rows);
61
- case 18:
111
+ case 19:
112
+ console.log("leave publishAguardandoAprovacaoSAP, rows size:".concat(rows.length));
113
+ return _context2.abrupt("return", rows);
114
+ case 21:
62
115
  case "end":
63
- return _context.stop();
116
+ return _context2.stop();
64
117
  }
65
- }, _callee);
118
+ }, _callee2);
66
119
  }));
67
- return function publishAguardandoAprovacaoSAP(_x) {
68
- return _ref2.apply(this, arguments);
120
+ return function publishAguardandoAprovacaoSAP(_x2) {
121
+ return _ref4.apply(this, arguments);
69
122
  };
70
123
  }();
71
124
  var query = function query(jql) {
@@ -77,11 +77,11 @@ var formatDateString = function formatDateString(str) {
77
77
  };
78
78
  var enrichComplement = exports.enrichComplement = /*#__PURE__*/function () {
79
79
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
80
- var issues, complementIssues, chunkedArray, pos, _iterator, _step, _step$value, i, array, promissesIndex, promissesSrv, _iterator2, _step2, _step2$value, index, key, responsesIdx, _iterator3, _step3, _step3$value, _index, issueKey, forms, formSrv, servicoFormId, responsesSrv, _iterator4, _step4, _step4$value, _index2, issue, servicoAnswers, foundSapCodFornecedor, sapCodFornecedor, foundSapCodeServico, sapCodeServico, foundTransacao, transacao, foundCodigoImposto, codigoImposto, foundGrupoCompradores, grupoCompradores, grupo_compradores_denominacao, foundContaRazao, contaRazao, foundTipoAlocacao, tipoAlocacao, foundCentroCusto, centroCusto, foundOrdInterna, ordInterna, foundImpostoSemRetencao, impostoSemRetencao;
80
+ var token, issues, complementIssues, chunkedArray, pos, _iterator, _step, _step$value, i, array, promissesIndex, promissesSrv, _iterator2, _step2, _step2$value, index, key, responsesIdx, _iterator3, _step3, _step3$value, _index, issueKey, forms, formSrv, servicoFormId, responsesSrv, _iterator4, _step4, _step4$value, _index2, issue, servicoAnswers, foundSapCodFornecedor, sapCodFornecedor, foundSapCodeServico, sapCodeServico, foundTransacao, transacao, foundCodigoImposto, codigoImposto, foundGrupoCompradores, grupoCompradores, grupo_compradores_denominacao, foundContaRazao, contaRazao, foundTipoAlocacao, tipoAlocacao, foundCentroCusto, centroCusto, foundOrdInterna, ordInterna, foundImpostoSemRetencao, impostoSemRetencao;
81
81
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
82
82
  while (1) switch (_context2.prev = _context2.next) {
83
83
  case 0:
84
- issues = _ref3.issues;
84
+ token = _ref3.token, issues = _ref3.issues;
85
85
  complementIssues = [];
86
86
  chunkedArray = chunkArray(issues, _constants.CHUNKSIZE);
87
87
  pos = 1;
@@ -101,7 +101,10 @@ var enrichComplement = exports.enrichComplement = /*#__PURE__*/function () {
101
101
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
102
102
  _step2$value = _slicedToArray(_step2.value, 2), index = _step2$value[0], key = _step2$value[1].key;
103
103
  console.log('chunk:%s/%s - %s/%s issueKey:%s', i, chunkedArray.length, pos++, issues.length, key);
104
- promissesIndex.push((0, _form_api.getFormIndex)(key));
104
+ promissesIndex.push((0, _form_api.getFormIndex)({
105
+ token: token,
106
+ issueKey: key
107
+ }));
105
108
  }
106
109
  } catch (err) {
107
110
  _iterator2.e(err);
@@ -123,6 +126,7 @@ var enrichComplement = exports.enrichComplement = /*#__PURE__*/function () {
123
126
  if (formSrv) {
124
127
  servicoFormId = formSrv.id;
125
128
  promissesSrv.push((0, _form_api.getFormSimplifiedAnswers)({
129
+ token: token,
126
130
  issueKey: issueKey,
127
131
  formId: servicoFormId
128
132
  }));