From 4860b2c0367b530f7e901db422ae167e02ac9669 Mon Sep 17 00:00:00 2001 From: "Luiz H. R. Silva" Date: Fri, 21 Jun 2024 13:47:22 -0300 Subject: [PATCH] removido registros undefined --- src/pilao-de-dados/_enviar_registros.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pilao-de-dados/_enviar_registros.ts b/src/pilao-de-dados/_enviar_registros.ts index b315b94..f02e6f6 100644 --- a/src/pilao-de-dados/_enviar_registros.ts +++ b/src/pilao-de-dados/_enviar_registros.ts @@ -1,7 +1,7 @@ import node_fetch from "cross-fetch" import type { tipoResposta } from "p-respostas" import { respostaComuns } from "p-respostas" -import { z } from "zod" +import { map, z } from "zod" import { PREFIXO, baseUrlPilao, @@ -48,7 +48,14 @@ export const enviar_registros = 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 = await node_fetch(url.toString(), { method: "POST", body: JSON.stringify({ tabela, registros: bloco }),