Skip to content

Commit

Permalink
Merge branch 'main' into feat/349-relatorio
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Aug 2, 2024
2 parents 7ba6776 + 730c510 commit 5e514af
Show file tree
Hide file tree
Showing 33 changed files with 861 additions and 617 deletions.
3 changes: 2 additions & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { TransacaoViewService } from './transacao-bq/transacao-view.service';
import { TransacaoViewModule } from './transacao-bq/transacao-view.module';
import { AppLoggerMiddleware } from './utils/logger-middleware';
import { RelatorioModule } from './relatorio/relatorio.module';
import { AppService } from './app.service';

@Module({
imports: [
Expand Down Expand Up @@ -124,7 +125,7 @@ import { RelatorioModule } from './relatorio/relatorio.module';
TransacaoViewModule,
RelatorioModule,
],
providers: [TransacaoViewService],
providers: [TransacaoViewService, AppService],
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
Expand Down
41 changes: 41 additions & 0 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { DataSource, Repository } from 'typeorm';
import { CustomLogger } from './utils/custom-logger';

@Injectable()
export class AppService implements OnModuleInit {
private logger: CustomLogger = new CustomLogger(AppService.name, {
timestamp: true,
});

constructor(@InjectDataSource() private dataSource: DataSource) {}

async onModuleInit() {
await this.applyHotfix();
}

async applyHotfix() {
const queryRunner = this.dataSource.createQueryRunner();
try {
this.logger.log('Applying preventive hotfix...');
await queryRunner.connect();
/**
* Unaccent
*
* Sometimes the unaccent extension is dropped with no reason so far.
* To prevent it, everytime Nest runs, it will re-install this extension.
*/
await queryRunner.query('DROP EXTENSION IF EXISTS unaccent');
await queryRunner.query('CREATE EXTENSION IF NOT EXISTS unaccent');
} catch (error) {
this.logger.error(
`Falha ao rodar o hotfix - ${error?.message}`,
error?.stack,
);
} finally {
await queryRunner.release();
this.logger.log('Preventive hotfix applied!');
}
}
}
5 changes: 4 additions & 1 deletion src/bank-statements/bank-statements.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IBSCounts } from './interfaces/bs-counts.interface';
import { IBSGetMePreviousDaysValidArgs } from './interfaces/bs-get-me-previous-days-args.interface';
import { IBSGetMePreviousDaysResponse } from './interfaces/bs-get-me-previous-days-response.interface';
import { DetalheA } from 'src/cnab/entity/pagamento/detalhe-a.entity';
import { ArquivoPublicacaoService } from 'src/cnab/service/arquivo-publicacao.service';

/**
* Get weekly statements
Expand All @@ -31,6 +32,7 @@ export class BankStatementsRepositoryService {
constructor(
private readonly transacaoViewService: TransacaoViewService,
private readonly detalheAService: DetalheAService,
private arquivoPublicacaoService: ArquivoPublicacaoService,
) {}

/**
Expand Down Expand Up @@ -126,7 +128,8 @@ export class BankStatementsRepositoryService {
endDate: endDate,
cpfCnpjs: [validArgs.user.getCpfCnpj()],
});
const revenues = transacoes.map((i) => i.toTicketRevenue());
const publicacoes = await this.arquivoPublicacaoService.findMany({ where: { itemTransacao: { itemTransacaoAgrupado: { id: In(transacoes.map(t => t.itemTransacaoAgrupadoId)) } } } });
const revenues = transacoes.map((i) => i.toTicketRevenue(publicacoes));
const detalhesA = await this.detalheAService.findMany({
itemTransacaoAgrupado: {
id: In(
Expand Down
4 changes: 2 additions & 2 deletions src/bigquery/repositories/bigquery-transacao.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ export class BigqueryTransacaoRepository {
if (args?.startDate) {
const startDate = args.startDate.toISOString().slice(0, 10);
queryBuilder.pushAND(
`DATE(t.datetime_processamento) >= DATE('${startDate}')`,
`DATE(t.datetime_processamento) >= DATE('${startDate} 00:00:00')`,
);
}
if (args?.endDate) {
const endDate = args.endDate.toISOString().slice(0, 10);
queryBuilder.pushAND(
`DATE(t.datetime_processamento) <= DATE('${endDate}')`,
`DATE(t.datetime_processamento) <= DATE('${endDate} 23:59:59')`,
);
}
if (args?.previousDaysOnly === true) {
Expand Down
96 changes: 46 additions & 50 deletions src/cnab/cnab.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PagamentosPendentesRepository } from 'src/cnab/repository/pagamento/pagamentos-pendentes.repository';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BanksModule } from 'src/banks/banks.module';
import { BigqueryModule } from 'src/bigquery/bigquery.module';
import { PagamentosPendentesRepository } from 'src/cnab/repository/pagamento/pagamentos-pendentes.repository';
import { LancamentoModule } from 'src/lancamento/lancamento.module';
import { SettingsModule } from 'src/settings/settings.module';
import { SftpModule } from 'src/sftp/sftp.module';
Expand All @@ -12,6 +12,10 @@ import { CnabController } from './cnab.controller';
import { CnabService } from './cnab.service';
import { ArquivoPublicacao } from './entity/arquivo-publicacao.entity';
import { ClienteFavorecido } from './entity/cliente-favorecido.entity';
import { DetalheAConf } from './entity/conference/detalhe-a-conf.entity';
import { DetalheBConf } from './entity/conference/detalhe-b-conf.entity';
import { HeaderArquivoConf } from './entity/conference/header-arquivo-conf.entity';
import { HeaderLoteConf } from './entity/conference/header-lote-conf.entity';
import { ExtratoDetalheE } from './entity/extrato/extrato-detalhe-e.entity';
import { ExtratoHeaderArquivo } from './entity/extrato/extrato-header-arquivo.entity';
import { ExtratoHeaderLote } from './entity/extrato/extrato-header-lote.entity';
Expand All @@ -23,6 +27,7 @@ import { ItemTransacaoAgrupado } from './entity/pagamento/item-transacao-agrupad
import { ItemTransacao } from './entity/pagamento/item-transacao.entity';
import { Ocorrencia } from './entity/pagamento/ocorrencia.entity';
import { Pagador } from './entity/pagamento/pagador.entity';
import { PagamentosPendentes } from './entity/pagamento/pagamentos-pendentes.entity';
import { TransacaoAgrupado } from './entity/pagamento/transacao-agrupado.entity';
import { Transacao } from './entity/pagamento/transacao.entity';
import { ArquivoPublicacaoRepository } from './repository/arquivo-publicacao.repository';
Expand All @@ -31,9 +36,13 @@ import { ExtratoDetalheERepository } from './repository/extrato/extrato-detalhe-
import { ExtratoHeaderArquivoRepository } from './repository/extrato/extrato-header-arquivo.repository';
import { ExtratoHeaderLoteRepository } from './repository/extrato/extrato-header-lote.repository';
import { OcorrenciaRepository } from './repository/ocorrencia.repository';
import { DetalheAConfRepository } from './repository/pagamento/detalhe-a-conf.repository';
import { DetalheARepository } from './repository/pagamento/detalhe-a.repository';
import { DetalheBConfRepository } from './repository/pagamento/detalhe-b-conf.repository';
import { DetalheBRepository } from './repository/pagamento/detalhe-b.repository';
import { HeaderArquivoConfRepository } from './repository/pagamento/header-arquivo-conf.repository';
import { HeaderArquivoRepository } from './repository/pagamento/header-arquivo.repository';
import { HeaderLoteConfRepository } from './repository/pagamento/header-lote-conf.repository';
import { HeaderLoteRepository } from './repository/pagamento/header-lote.repository';
import { ItemTransacaoAgrupadoRepository } from './repository/pagamento/item-transacao-agrupado.repository';
import { ItemTransacaoRepository } from './repository/pagamento/item-transacao.repository';
Expand All @@ -46,40 +55,31 @@ import { ExtratoDetalheEService } from './service/extrato/extrato-detalhe-e.serv
import { ExtratoHeaderArquivoService } from './service/extrato/extrato-header-arquivo.service';
import { ExtratoHeaderLoteService } from './service/extrato/extrato-header-lote.service';
import { OcorrenciaService } from './service/ocorrencia.service';
import { DetalheAConfService } from './service/pagamento/detalhe-a-conf.service';
import { DetalheAService } from './service/pagamento/detalhe-a.service';
import { DetalheBConfService } from './service/pagamento/detalhe-b-conf.service';
import { DetalheBService } from './service/pagamento/detalhe-b.service';
import { HeaderArquivoConfService } from './service/pagamento/header-arquivo-conf.service';
import { HeaderArquivoService } from './service/pagamento/header-arquivo.service';
import { HeaderLoteConfService } from './service/pagamento/header-lote-conf.service';
import { HeaderLoteService } from './service/pagamento/header-lote.service';
import { ItemTransacaoAgrupadoService } from './service/pagamento/item-transacao-agrupado.service';
import { ItemTransacaoService } from './service/pagamento/item-transacao.service';
import { PagadorService } from './service/pagamento/pagador.service';
import { PagamentosPendentesService } from './service/pagamento/pagamentos-pendentes.service';
import { RemessaRetornoService } from './service/pagamento/remessa-retorno.service';
import { TransacaoAgrupadoService } from './service/pagamento/transacao-agrupado.service';
import { TransacaoService } from './service/pagamento/transacao.service';
import { DetalheAConfRepository } from './repository/pagamento/detalhe-a-conf.repository';
import { DetalheBConfRepository } from './repository/pagamento/detalhe-b-conf.repository';
import { HeaderArquivoConfRepository } from './repository/pagamento/header-arquivo-conf.repository';
import { HeaderLoteConfRepository } from './repository/pagamento/header-lote-conf.repository';
import { DetalheAConfService } from './service/pagamento/detalhe-a-conf.service';
import { DetalheBConfService } from './service/pagamento/detalhe-b-conf.service';
import { HeaderArquivoConfService } from './service/pagamento/header-arquivo-conf.service';
import { HeaderLoteConfService } from './service/pagamento/header-lote-conf.service';
import { DetalheAConf } from './entity/conference/detalhe-a-conf.entity';
import { DetalheBConf } from './entity/conference/detalhe-b-conf.entity';
import { HeaderArquivoConf } from './entity/conference/header-arquivo-conf.entity';
import { HeaderLoteConf } from './entity/conference/header-lote-conf.entity';
import { PagamentosPendentes } from './entity/pagamento/pagamentos-pendentes.entity';
import { PagamentosPendentesService } from './service/pagamento/pagamentos-pendentes.service';

@Module({
imports: [
UsersModule,
SftpModule,
BanksModule,
BigqueryModule,
LancamentoModule,
SettingsModule,
SftpModule,
TransacaoViewModule,
UsersModule,
TypeOrmModule.forFeature([
HeaderArquivoConf,
HeaderLoteConf,
Expand All @@ -104,50 +104,48 @@ import { PagamentosPendentesService } from './service/pagamento/pagamentos-pende
]),
],
providers: [
ArquivoPublicacaoRepository,
ArquivoPublicacaoService,
ClienteFavorecidoRepository,
ClienteFavorecidoService,
CnabService,
HeaderArquivoRepository,
HeaderArquivoService,
HeaderLoteRepository,
HeaderLoteService,
DetalheAConfRepository,
DetalheAConfService,
DetalheARepository,
DetalheAService,
DetalheBConfRepository,
DetalheBConfService,
DetalheBRepository,
DetalheBService,
PagamentosPendentesRepository,
PagamentosPendentesService,

ExtratoDetalheERepository,
ExtratoDetalheEService,
ExtratoHeaderArquivoRepository,
ExtratoHeaderArquivoService,
ExtratoHeaderLoteRepository,
ExtratoHeaderLoteService,
HeaderArquivoConfRepository,
HeaderArquivoConfService,
HeaderArquivoRepository,
HeaderArquivoService,
HeaderLoteConfRepository,
HeaderLoteConfService,
DetalheAConfRepository,
DetalheAConfService,
DetalheBConfRepository,
DetalheBConfService,

ClienteFavorecidoRepository,
ClienteFavorecidoService,
HeaderLoteRepository,
HeaderLoteService,
ItemTransacaoAgrupadoRepository,
ItemTransacaoAgrupadoService,
ItemTransacaoRepository,
ItemTransacaoService,
OcorrenciaRepository,
OcorrenciaService,
PagadorRepository,
PagadorService,
ArquivoPublicacaoRepository,
ArquivoPublicacaoService,
TransacaoRepository,
TransacaoService,
PagamentosPendentesRepository,
PagamentosPendentesService,
RemessaRetornoService,
TransacaoAgrupadoRepository,
TransacaoAgrupadoService,
OcorrenciaRepository,
OcorrenciaService,
ItemTransacaoRepository,
ItemTransacaoService,
ItemTransacaoAgrupadoRepository,
ItemTransacaoAgrupadoService,
ExtratoHeaderArquivoRepository,
ExtratoHeaderArquivoService,
ExtratoHeaderLoteRepository,
ExtratoHeaderLoteService,
ExtratoDetalheERepository,
ExtratoDetalheEService,
RemessaRetornoService,
TransacaoRepository,
TransacaoService,
],
exports: [
CnabService,
Expand All @@ -159,7 +157,6 @@ import { PagamentosPendentesService } from './service/pagamento/pagamentos-pende
DetalheAService,
DetalheBRepository,
DetalheBService,

HeaderArquivoConfRepository,
HeaderArquivoConfService,
HeaderLoteConfRepository,
Expand All @@ -170,7 +167,6 @@ import { PagamentosPendentesService } from './service/pagamento/pagamentos-pende
DetalheBConfService,
PagamentosPendentesRepository,
PagamentosPendentesService,

ClienteFavorecidoRepository,
ClienteFavorecidoService,
PagadorRepository,
Expand Down
Loading

0 comments on commit 5e514af

Please sign in to comment.