Skip to content

Commit

Permalink
upd listcobs
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptographix committed May 6, 2024
1 parent ba05fa9 commit ebd3403
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 14 deletions.
18 changes: 10 additions & 8 deletions packages/api-pix/src/api-client/cob-client.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { Fetcher, IJSONFetcher, FetchQueryParams } from './mod.ts';
import { Cobranca, PartialCobranca, CobType, PagedListCobParams } from '../deps.ts';
import { Cobranca, PartialCobranca, CobType, PagedListCobParams, CobsList } from '../deps.ts';

export class CobClient {
constructor( public readonly fetcher: IJSONFetcher, public readonly cobType: CobType, public additionalQuery?: FetchQueryParams ) {
//
}

async getCobs( params: PagedListCobParams ): Promise<Cobranca[]> {
const pag = params.paginacao ?? {};


async getCobs( params?: PagedListCobParams ): Promise<CobsList> {
const pag = params?.paginacao ?? {};

//Object.keys(params).forEach(key => obj[key] === undefined ? delete obj[key] : {});

const query: Record<string,string|undefined> = {
inicio: params?.inicio.toISOString().slice(0,-5)+"Z",
fim: params?.fim.toISOString().slice(0,-5)+"Z",
cpf: params.cpf,
cnpj: params.cnpj,
locationPresente: (params.locationPresente != undefined) ? (params.locationPresente ? "true":"false"):undefined,
status: params.status,
cpf: params?.cpf,
cnpj: params?.cnpj,
locationPresente: (params?.locationPresente != undefined) ? (params.locationPresente ? "true":"false"):undefined,
status: params?.status,
"paginacao.paginaAtual": (pag.paginaAtual !== undefined) ? ""+pag.paginaAtual : undefined,
"paginacao.itensPorPagina": (pag.itensPorPagina !== undefined) ? ""+pag.itensPorPagina : undefined,
};
Expand All @@ -27,7 +29,7 @@ export class CobClient {

const path = Fetcher.buildFetchPath( `${this.cobType}`, q2 );

const cobs = await this.fetcher.fetchJSON<Cobranca[]>( "GET", path );
const cobs = await this.fetcher.fetchJSON<CobsList>( "GET", path );

return cobs;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api-pix/src/api-client/json-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class JSONFetcher implements IJSONFetcher {
json = await resp.json();

if (this.options.debug) {
console.log("Body:", json);
console.log("Body:", JSON.stringify(json, null, 2));
}
}

Expand Down
45 changes: 42 additions & 3 deletions packages/api-pix/test/test-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Deno.test({
debug: true,

// these are mine ..
...(await import("./test-credentials.ts")).banrisulHomolNascentMTLS//banrisulHomolNascentORG// banrisulHomolNascentMTLS // NascentMTLS // banrisulHomolSeanTLS// Nascent,// DevSean, //siCoob, // bancoDoBrasil, //gerenciaNet, //banrisulDev, //
...(await import("./test-credentials.ts")).banrisulProduction
//.banrisulHomolJairoMTLS
// banrisulHomolNascentMTLS//banrisulHomolNascentORG// banrisulHomolNascentMTLS // NascentMTLS // banrisulHomolSeanTLS// Nascent,// DevSean, //siCoob, // bancoDoBrasil, //gerenciaNet, //banrisulDev, //
};
const token = await authenticate(config);
const fetcher = getFetcher(config, token);
Expand All @@ -54,15 +56,52 @@ Deno.test({
gwAppKey ? { "gw-dev-app-key": gwAppKey } : undefined
);

for (let i = 0; i < 1; ++i) {
let items = 0;
const itensPorPagina = 1000;
let paginaAtual = Math.trunc(0 / itensPorPagina);
let totalItems = -1;

paginaAtual = 1;
while( totalItems == -1 || items <= totalItems ) {
const t = new Date();

//if (paginaAtual == 4) break;

const cobsIn = await client.getCobs( {
inicio: new Date("Thu, 1 Jan 2024 00:00:00 GMT"),
fim: new Date(),
paginacao: {
itensPorPagina,
paginaAtual,
}
});

const pag = cobsIn.parametros.paginacao?.paginaAtual ?? 0;
totalItems = cobsIn.parametros.paginacao?.quantidadeTotalDeItens;

if ( pag != paginaAtual )
break;
if (cobsIn.cobs.length == 0)
break;
items += cobsIn.cobs.length;

paginaAtual = pag + 1;
console.log( "Page: " + paginaAtual, " = " + (new Date().getTime() - t.getTime() ) + "ms");

// break;
}

console.log( "Total: ", items);

for (let i = 0; i < 0; ++i) {
let txid: string = crypto.randomUUID();
txid = txid.replaceAll("-", "");
//console.log( txid );
//txid = '44858987833e4015b3447e6bbc057a1a' //'8cd912d5293d417fbf4ec3702df20ea9'
//txid = 'd62083b450ed4d0a9efe8f983c145ff4';

///*
let cobIn = await client.putCob(txid, {
const cobIn = await client.putCob(txid, {
...testCob_Nascent,
chave: "9e25c9c1-27f9-4cc6-9263-03080110dc83",
infoAdicionais: undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Status } from '../../cobranca/mod.ts';
import { Cobranca, Status } from '../../cobranca/mod.ts';
import { Paginacao } from '../paginacao.ts';

export interface ListCobParams {
Expand All @@ -15,10 +15,22 @@ export interface ListCobParams {
//
status?: Status;
//
loteCobvId?: Number;
loteCobvId?: number;
}

export interface ResultPaginacao extends Paginacao {
quantidadeDePaginas: number;
quantidadeTotalDeItens: number;
}

export interface PagedListCobParams extends ListCobParams {
//
paginacao?: Paginacao;
}

export interface CobsList {
parametros: {
paginacao: ResultPaginacao;
},
cobs: Cobranca[];
}

1 comment on commit ebd3403

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on ebd3403 May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

BOOT_FAILURE

Uncaught SyntaxError: The requested module 'https://deno.land/x/oak/mod.ts' does not provide an export named 'helpers'
    at file:///src/packages/pix-server/server/api-pix-server/helpers.ts:1:10

Please sign in to comment.