Skip to content

Commit

Permalink
Merge pull request #520 from RJ-SMTR/hotfix/transacao-tec
Browse files Browse the repository at this point in the history
Hotfix/transacao-tec
  • Loading branch information
williamfl2007 authored Oct 28, 2024
2 parents 3c23047 + 060aa80 commit 302718d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/bigquery/repositories/bigquery-transacao.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IBqFindTransacao {
valor_pagamento?: number[] | null | ['>=' | '<=' | '>' | '<', number] | 'NOT NULL';
id_transacao?: string[] | null;
id_operadora?: string[];
nomeConsorcio?: { in?: string[], notIn?: string[]};
}

@Injectable()
Expand Down Expand Up @@ -78,7 +79,7 @@ export class BigqueryTransacaoRepository {
t.valor_pagamento,
t.versao AS bqDataVersion,
t.consorcio,
t.operadora,
o.operadora_completo AS operadora,
t.id_consorcio,
t.id_operadora,
o.documento AS operadoraCpfCnpj,
Expand Down Expand Up @@ -138,6 +139,12 @@ export class BigqueryTransacaoRepository {
if (args?.previousDaysOnly === true) {
queryBuilder.pushAND('DATE(t.datetime_processamento) > DATE(t.datetime_transacao)');
}
if (args?.nomeConsorcio?.in?.length) {
queryBuilder.pushAND(`t.consorcio IN ('${args.nomeConsorcio.in.join("','")}')`);
}
if (args?.nomeConsorcio?.notIn?.length) {
queryBuilder.pushAND(`t.consorcio NOT IN ('${args.nomeConsorcio.notIn.join("','")}')`);
}
if (args?.valor_pagamento !== undefined) {
const _value = args.valor_pagamento;
let value = '';
Expand Down
3 changes: 2 additions & 1 deletion src/bigquery/services/bigquery-transacao.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export class BigqueryTransacaoService {
*
* @param [daysBack=0] Pega a semana atual ou N dias atrás.
*/
public async getFromWeek(dataOrdemInicial: Date, dataOrdemFinal: Date, daysBack = 0): Promise<BigqueryTransacao[]> {
public async getFromWeek(dataOrdemInicial: Date, dataOrdemFinal: Date, daysBack = 0, filter?: IBqFindTransacao): Promise<BigqueryTransacao[]> {
const transacao = (
await this.bigqueryTransacaoRepository.findMany({
startDate: dataOrdemInicial,
endDate: dataOrdemFinal,
...(filter ? filter : {}),
})
).map((i) => ({ ...i } as BigqueryTransacao));
return transacao;
Expand Down
2 changes: 1 addition & 1 deletion src/cnab/cnab-manutencao.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class CnabManutencaoController {
@ApiBearerAuth()
@ApiQuery({ name: 'dataOrdemInicial', type: Date, required: true, description: 'Data da Ordem de Pagamento Inicial' })
@ApiQuery({ name: 'dataOrdemFinal', type: Date, required: true, description: 'Data da Ordem de Pagamento Final' })
@ApiQuery({ name: 'consorcio', type: String, required: false, description: ApiDescription({ _: 'Nome do consorcio - salvar transações', default: 'Todos' }), example: 'Todos / Van / Empresa /Nome Consorcio' })
@ApiQuery({ name: 'consorcio', type: String, required: false, description: ApiDescription({ _: 'Nome do consorcio - salvar transações', default: 'Todos' }), example: 'Todos / Van / Empresa / Nome Consorcio' })
@ApiQuery({ name: 'idTransacao', type: String, required: false, description: 'Lista de idTransacao para atualizar' })
async getUpdateTransacaoViewBigquery(
@Query('dataOrdemInicial', new ParseDatePipe({ transform: true })) dataOrdemInicial: any, //
Expand Down
12 changes: 7 additions & 5 deletions src/cnab/cnab.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,16 @@ export class CnabService {
}

async findBigqueryTransacao(dataOrdemIncial: Date, dataOrdemFinal: Date, daysBack = 0, consorcio: string): Promise<BigqueryTransacao[]> {
const transacoesBq = await this.bigqueryTransacaoService.getFromWeek(startOfDay(dataOrdemIncial), endOfDay(dataOrdemFinal), daysBack);
let trs = transacoesBq;
const nomeConsorcio: { in: string[], notIn: string[] } = {in: [], notIn: [] };
if (consorcio === 'Van') {
trs = transacoesBq.filter((tr) => tr.consorcio === 'STPC' || tr.consorcio === 'STPL');
nomeConsorcio.in = ['STPC', 'STPL', 'TEC'];
} else if (consorcio == 'Empresa') {
trs = transacoesBq.filter((tr) => tr.consorcio !== 'STPC' && tr.consorcio !== 'STPL');
nomeConsorcio.notIn = ['STPC', 'STPL', 'TEC'];
} else if (consorcio != 'Todos') {
nomeConsorcio.in = consorcio.split(',');
}
return trs;
const transacoesBq = await this.bigqueryTransacaoService.getFromWeek(startOfDay(dataOrdemIncial), endOfDay(dataOrdemFinal), daysBack, { nomeConsorcio });
return transacoesBq;
}

// #region saveOrdens
Expand Down

0 comments on commit 302718d

Please sign in to comment.