removido registros undefined

This commit is contained in:
Luiz H. R. Silva 2024-06-21 13:47:59 -03:00
parent 4860b2c036
commit ceab73c21c
4 changed files with 29 additions and 4 deletions

View file

@ -30,7 +30,9 @@ export const enviar_registros = ({ conta, produto, emDesenvolvimento }) => ({ re
const url = new URL(`${baseUrlPilao(emDesenvolvimento)}${PREFIXO}/${Object.keys({ enviar_registros })[0]}/${produto}/${conta}`);
const tamanhoBlocos = 1000;
while (registros.length > 0) {
const bloco = registros.splice(0, tamanhoBlocos);
const bloco = registros
.splice(0, tamanhoBlocos)
.map((r) => Object.fromEntries(Object.entries(r).map(([k, v]) => [k, v === undefined ? null : v])));
const resp = yield node_fetch(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela, registros: bloco }),

View file

@ -35,6 +35,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
@ -73,7 +89,14 @@ var enviar_registros = function (_a) {
_b.label = 1;
case 1:
if (!(registros.length > 0)) return [3 /*break*/, 3];
bloco = registros.splice(0, tamanhoBlocos);
bloco = registros
.splice(0, tamanhoBlocos)
.map(function (r) {
return Object.fromEntries(Object.entries(r).map(function (_a) {
var _b = __read(_a, 2), k = _b[0], v = _b[1];
return [k, v === undefined ? null : v];
}));
});
return [4 /*yield*/, (0, cross_fetch_1.default)(url.toString(), {
method: "POST",
body: JSON.stringify({ tabela: tabela, registros: bloco }),

View file

@ -1,6 +1,6 @@
{
"name": "p-drives",
"version": "0.84.0",
"version": "0.86.0",
"description": "",
"main": "src/index.ts",
"exports": {

View file

@ -1,7 +1,7 @@
import node_fetch from "cross-fetch"
import type { tipoResposta } from "p-respostas"
import { respostaComuns } from "p-respostas"
import { map, z } from "zod"
import { z } from "zod"
import {
PREFIXO,
baseUrlPilao,