Skip to content

Commit

Permalink
Merge pull request #459 from RJ-SMTR/feat/234-lancamento
Browse files Browse the repository at this point in the history
Feat/234-lancamento
  • Loading branch information
williamfl2007 authored Sep 10, 2024
2 parents 12f87b9 + ec8bdef commit 4e4e7f4
Show file tree
Hide file tree
Showing 124 changed files with 2,403 additions and 1,682 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
branches:
- "main"
paths-ignore:
- 'README.md'
- 'docs'

env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/cd_stag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- "release/*"
- "devops"
- "develop"
paths-ignore:
- 'README.md'
- 'docs'

env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [develop]
pull_request:
branches: [develop]
paths-ignore:
- 'README.md'
- 'docs'

jobs:
lint:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [main]
pull_request:
branches: [main]
paths-ignore:
- 'README.md'
- 'docs'

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-cct",
"version": "0.12.7",
"version": "0.13.0",
"description": "",
"author": "",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import { SftpModule } from './sftp/sftp.module';
import { TestModule } from './test/test.module';
import { TicketRevenuesModule } from './ticket-revenues/ticket-revenues.module';
import { UsersModule } from './users/users.module';
import { TransacaoViewService } from './transacao-bq/transacao-view.service';
import { TransacaoViewModule } from './transacao-bq/transacao-view.module';
import { TransacaoViewService } from './transacao-view/transacao-view.service';
import { TransacaoViewModule } from './transacao-view/transacao-view.module';
import { AppLoggerMiddleware } from './utils/logger-middleware';
import { RelatorioModule } from './relatorio/relatorio.module';
import { AppService } from './app.service';
Expand Down
12 changes: 5 additions & 7 deletions src/bank-statements/bank-statements.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TimeIntervalEnum } from 'src/utils/enums/time-interval.enum';
import { getPagination } from 'src/utils/get-pagination';
import { IRequest } from 'src/utils/interfaces/request.interface';
import { ParseNumberPipe } from 'src/utils/pipes/parse-number.pipe';
import { ValidateEnumPipe } from 'src/utils/pipes/validate-enum.pipe';
import { ParseEnumPipe } from 'src/utils/pipes/parse-enum.pipe';
import { DateQueryParams } from 'src/utils/query-param/date.query-param';
import { PaginationQueryParams } from 'src/utils/query-param/pagination.query-param';
import { getRequestLog } from 'src/utils/request-utils';
Expand Down Expand Up @@ -60,12 +60,10 @@ export class BankStatementsController {
@ApiQuery(CommonApiParams.userId)
@HttpCode(HttpStatus.OK)
async getMe(
@Request() request: IRequest,
@Request() request: IRequest, //
@Query(...DateQueryParams.yearMonth) yearMonth: string,
@Query('timeInterval', new ValidateEnumPipe(BSMeTimeIntervalEnum, false, BSMeTimeIntervalEnum.LAST_MONTH))
timeInterval?: BSMeTimeIntervalEnum | undefined,
@Query('userId', new ParseNumberPipe({ min: 1, optional: true }))
userId?: number | null,
@Query('timeInterval', new ParseEnumPipe(BSMeTimeIntervalEnum, { optional: true, defaultValue: BSMeTimeIntervalEnum.LAST_MONTH })) timeInterval: BSMeTimeIntervalEnum | undefined,
@Query('userId', new ParseNumberPipe({ min: 1, optional: true })) userId?: number | null,
): Promise<IBSGetMeResponse> {
this.logger.log(getRequestLog(request));

Expand Down Expand Up @@ -118,7 +116,7 @@ export class BankStatementsController {
@Query(...PaginationQueryParams.page) page: number,
@Query(...PaginationQueryParams.limit) limit: number,
@Query('endDate', new ParseDatePipe()) endDate: string,
@Query('timeInterval', new ValidateEnumPipe(BSMePrevDaysTimeIntervalEnum, true)) timeInterval: BSMePrevDaysTimeIntervalEnum,
@Query('timeInterval', new ParseEnumPipe(BSMePrevDaysTimeIntervalEnum)) timeInterval: BSMePrevDaysTimeIntervalEnum,
@Query('userId', new ParseNumberPipe({ min: 1, optional: true })) userId?: number | null,
): Promise<Pagination<IBSGetMePreviousDaysResponse>> {
const isUserIdParam = userId !== null && !isNaN(Number(userId));
Expand Down
2 changes: 1 addition & 1 deletion src/bank-statements/bank-statements.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BankStatementsRepositoryService } from './bank-statements.repository';
import { BankStatementsController } from './bank-statements.controller';
import { BankStatementsService } from './bank-statements.service';
import { CnabModule } from 'src/cnab/cnab.module';
import { TransacaoViewModule } from 'src/transacao-bq/transacao-view.module';
import { TransacaoViewModule } from 'src/transacao-view/transacao-view.module';

@Module({
providers: [BankStatementsService, BankStatementsRepositoryService],
Expand Down
23 changes: 4 additions & 19 deletions src/bigquery/dtos/bigquery-ordem-pagamento.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
IsDateString,
IsNotEmpty,
IsNumber,
IsNumberString,
IsString,
ValidateIf,
} from 'class-validator';
import { IsDateString, IsNotEmpty, IsNumber, IsNumberString, IsString, ValidateIf } from 'class-validator';
import { isSameDay, nextFriday } from 'date-fns';
import { TipoFavorecidoEnum } from 'src/tipo-favorecido/tipo-favorecido.enum';
import { TipoFavorecidoEnum } from 'src/cnab/enums/tipo-favorecido.enum';
import { DeepPartial } from 'typeorm';

/**
Expand Down Expand Up @@ -158,16 +151,8 @@ export class BigqueryOrdemPagamentoDTO {

tipoFavorecido: TipoFavorecidoEnum | null;

public static findAgrupado(
ordemAgs: BigqueryOrdemPagamentoDTO[],
ordem: BigqueryOrdemPagamentoDTO,
newDataOrdem = nextFriday(new Date()),
) {
const filtered = ordemAgs.filter(
(i) =>
isSameDay(new Date(i.dataOrdem), newDataOrdem) &&
i.idConsorcio === ordem.idConsorcio,
)[0];
public static findAgrupado(ordemAgs: BigqueryOrdemPagamentoDTO[], ordem: BigqueryOrdemPagamentoDTO, newDataOrdem = nextFriday(new Date())) {
const filtered = ordemAgs.filter((i) => isSameDay(new Date(i.dataOrdem), newDataOrdem) && i.idConsorcio === ordem.idConsorcio)[0];
return filtered ? filtered : null;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TipoFavorecidoEnum } from 'src/tipo-favorecido/tipo-favorecido.enum';
import { TipoFavorecidoEnum } from 'src/cnab/enums/tipo-favorecido.enum';

export interface IBigqueryFindOrdemPagamento {
operadorCpfs?: string[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Injectable, Logger } from '@nestjs/common';
import { SettingsService } from 'src/settings/settings.service';
import { Injectable } from '@nestjs/common';
import { CustomLogger } from 'src/utils/custom-logger';
import { bigToNumber } from 'src/utils/pipe-utils';
import { BigquerySource, BigqueryService } from '../bigquery.service';
import { BigqueryService, BigquerySource } from '../bigquery.service';
import { BigqueryOrdemPagamento } from '../entities/ordem-pagamento.bigquery-entity';
import { IBigqueryFindOrdemPagamento } from '../interfaces/bigquery-find-ordem-pagamento.interface';
import { CustomLogger } from 'src/utils/custom-logger';

@Injectable()
export class BigqueryOrdemPagamentoRepository {
private logger = new CustomLogger('BigqueryOrdemPagamentoRepository', { timestamp: true });

constructor(
private readonly bigqueryService: BigqueryService,
private readonly settingsService: SettingsService,
) {}

public async findMany(
Expand Down Expand Up @@ -87,6 +85,7 @@ export class BigqueryOrdemPagamentoRepository {
const select = `
SELECT
CAST(t.data_ordem AS STRING) AS dataOrdem,
CAST(t.data_pagamento AS STRING) AS dataPagamento,
t.id_consorcio AS idConsorcio,
t.consorcio,
t.id_operadora AS idOperadora,
Expand Down
13 changes: 13 additions & 0 deletions src/cnab/cliente-favorecido.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ClienteFavorecido } from './entity/cliente-favorecido.entity';
import { ClienteFavorecidoRepository } from './repository/cliente-favorecido.repository';
import { ClienteFavorecidoService } from './service/cliente-favorecido.service';

@Module({
imports: [TypeOrmModule.forFeature([ClienteFavorecido])],
providers: [ClienteFavorecidoRepository, ClienteFavorecidoService],
exports: [ClienteFavorecidoRepository, ClienteFavorecidoService],
controllers: [],
})
export class ClienteFavorecidoModule {}
58 changes: 51 additions & 7 deletions src/cnab/cnab-manutencao.controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BadRequestException, Controller, Get, HttpCode, HttpStatus, ParseArrayPipe, Query, UseGuards } from '@nestjs/common';
import { BadRequestException, Controller, Get, HttpCode, HttpStatus, Query, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import { Roles } from 'src/roles/roles.decorator';
import { RoleEnum } from 'src/roles/roles.enum';
import { RolesGuard } from 'src/roles/roles.guard';
import { ApiDescription } from 'src/utils/api-param/description-api-param';
import { CustomLogger } from 'src/utils/custom-logger';
import { ParseArrayPipe } from 'src/utils/pipes/parse-array.pipe';
import { ParseDatePipe } from 'src/utils/pipes/parse-date.pipe';
import { ParseListPipe } from 'src/utils/pipes/parse-list.pipe';
import { ParseNumberPipe } from 'src/utils/pipes/parse-number.pipe';
import { CnabService } from './cnab.service';

Expand All @@ -21,7 +21,51 @@ export class CnabManutencaoController {

constructor(private readonly cnabService: CnabService) {}

@Get('generateRemessa')
@Get('generateRemessaLancamento')
@HttpCode(HttpStatus.OK)
@UseGuards(AuthGuard('jwt'), RolesGuard)
@Roles(RoleEnum.master)
@ApiOperation({ description: 'Feito para manutenção pelos admins.\n\nExecuta a geração e envio de remessa - que normalmente é feita via cronjob.' })
@ApiQuery({ name: 'dataOrdemInicial', type: String, required: false, description: ApiDescription({ _: 'Data da Ordem de Pagamento Inicial - salvar transações', example: '2024-07-15' }) })
@ApiQuery({ name: 'dataOrdemFinal', type: String, required: false, description: ApiDescription({ _: 'Data da Ordem de Pagamento Final - salvar transações', example: '2024-07-16' }) })
@ApiQuery({ name: 'dataPagamento', type: String, required: false, description: ApiDescription({ _: 'Data de pagamento', default: 'O dia de hoje' }) })
@ApiQuery({ name: 'isConference', type: Boolean, required: true, description: 'Conferencia - Se o remessa será gerado numa tabela de teste.', example: true })
@ApiQuery({ name: 'isCancelamento', type: Boolean, required: true, description: 'Cancelamento', example: false })
@ApiQuery({ name: 'nsaInicial', type: Number, required: false, description: ApiDescription({ default: 'O NSA atual' }) })
@ApiQuery({ name: 'nsaFinal', type: Number, required: false, description: ApiDescription({ default: 'nsaInicial' }) })
@ApiQuery({ name: 'dataCancelamento', type: String, required: false, description: ApiDescription({ _: 'Data de vencimento da transação a ser cancelada (DetalheA).', 'Required if': 'isCancelamento = true' }), example: '2024-07-16' })
@ApiBearerAuth()
async getGenerateRemessaLancamento(
@Query('dataOrdemInicial', new ParseDatePipe({ transform: true, optional: true })) _dataOrdemInicial: any, // Date
@Query('dataOrdemFinal', new ParseDatePipe({ transform: true, optional: true })) _dataOrdemFinal: any, // Date
@Query('dataPagamento', new ParseDatePipe({ transform: true, optional: true })) dataPagamento: Date | undefined, // Date | undefined
@Query('isConference') isConference: boolean,
@Query('isCancelamento') isCancelamento: boolean,
@Query('nsaInicial', new ParseNumberPipe({ min: 1, optional: true })) nsaInicial: number | undefined,
@Query('nsaFinal', new ParseNumberPipe({ min: 1, optional: true })) nsaFinal: number | undefined,
@Query('dataCancelamento', new ParseDatePipe({ transform: true, optional: true })) _dataCancelamento: any, // Date | undefined
) {
const dataOrdemInicial = _dataOrdemInicial as Date | undefined;
const dataOrdemFinal = _dataOrdemFinal as Date | undefined;
const dataCancelamento = _dataCancelamento as Date | undefined;

if (isCancelamento && !dataCancelamento) {
throw new BadRequestException('dataCancelamento é obrigatório se isCancelamento = true');
}

return await this.cnabService.getGenerateRemessaLancamento({
dataOrdemInicial,
dataOrdemFinal,
dataPgto: dataPagamento,
isConference,
isCancelamento,
nsaInicial,
nsaFinal,
dataCancelamento,
});
}

@Get('generateRemessaJae')
@HttpCode(HttpStatus.OK)
@UseGuards(AuthGuard('jwt'), RolesGuard)
@Roles(RoleEnum.master)
Expand All @@ -37,7 +81,7 @@ export class CnabManutencaoController {
@ApiQuery({ name: 'nsaFinal', description: ApiDescription({ default: 'nsaInicial' }), required: false, type: Number })
@ApiQuery({ name: 'dataCancelamento', description: ApiDescription({ _: 'Data de vencimento da transação a ser cancelada (DetalheA).', 'Required if': 'isCancelamento = true' }), required: false, type: String, example: '2024-07-16' })
@ApiBearerAuth()
async getGenerateRemessa(
async getGenerateRemessaJae(
@Query('dataOrdemInicial', new ParseDatePipe({ transform: true })) _dataOrdemInicial: any, // Date
@Query('dataOrdemFinal', new ParseDatePipe({ transform: true })) _dataOrdemFinal: any, // Date
@Query('diasAnterioresOrdem', new ParseNumberPipe({ min: 0, defaultValue: 0 })) diasAnteriores: number,
Expand All @@ -58,7 +102,7 @@ export class CnabManutencaoController {
throw new BadRequestException('dataCancelamento é obrigatório se isCancelamento = true');
}

return await this.cnabService.getGenerateRemessa({
return await this.cnabService.getGenerateRemessaJae({
dataOrdemInicial,
dataOrdemFinal,
diasAnteriores,
Expand Down Expand Up @@ -99,7 +143,7 @@ export class CnabManutencaoController {
async getSyncTransacaoViewOrdemPgto(
@Query('dataOrdemInicial', new ParseDatePipe({ transform: true, optional: true })) dataOrdemInicial: Date | undefined, //
@Query('dataOrdemFinal', new ParseDatePipe({ transform: true, optional: true })) dataOrdemFinal: Date | undefined,
@Query('nomeFavorecido', new ParseListPipe({ transform: true, optional: true })) nomeFavorecido: string[] | undefined,
@Query('nomeFavorecido', new ParseArrayPipe({ transform: true, optional: true })) nomeFavorecido: string[] | undefined,
) {
const dataOrdem_between = dataOrdemInicial && dataOrdemFinal && ([dataOrdemInicial, dataOrdemFinal] as [Date, Date]);
return await this.cnabService.syncTransacaoViewOrdemPgto({ dataOrdem_between, nomeFavorecido });
Expand All @@ -119,7 +163,7 @@ export class CnabManutencaoController {
@Query('dataOrdemInicial', new ParseDatePipe({ transform: true })) dataOrdemInicial: any, //
@Query('dataOrdemFinal', new ParseDatePipe({ transform: true })) dataOrdemFinal: any,
@Query('consorcio') consorcio: string | undefined,
@Query('idTransacao', new ParseArrayPipe({ items: String, separator: ',', optional: true })) idTransacao: string[], //
@Query('idTransacao', new ParseArrayPipe({ optional: true })) idTransacao: string[], //
) {
const _dataOrdemInicial: Date = dataOrdemInicial;
const _dataOrdemFinal: Date = dataOrdemFinal;
Expand Down
Loading

0 comments on commit 4e4e7f4

Please sign in to comment.