Skip to content

Commit

Permalink
feat: migration ClienteFavorecido
Browse files Browse the repository at this point in the history
  • Loading branch information
yxuo committed Mar 6, 2024
1 parent 4709cb6 commit e1a4188
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 40 deletions.
17 changes: 15 additions & 2 deletions src/bigquery/entities/ordem-pagamento.bigquery-entity.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { HttpStatus } from "@nestjs/common";
import { CommonHttpException } from "src/utils/http-exception/common-http-exception";

/**
* Logic:
* - It has 1 `id_ordem_pagamento` per day.
* - id_ordem_pagamento repeats by combination of id_consorcio (CNPJ), id_operadora (CPF), servico (vehicle)
*/
export class BigqueryOrdemPagamento {
/** Data da ordem de pagamento (partição) */
data_ordem: string | null;

/** Data de pagamento da ordem */
data_pagamento: string | null;

/** Nome cadastro.consorcios */
/**
* Id de cadastro.consorcios
*
* id_consorcio.cnpj = CNPJ
*/
id_consorcio: string | null;

/** Nome do consórcio */
consorcio: string | null;

/** Identificador da operadora na tabela cadastro.operadoras */
/**
* Identificador da operadora na tabela cadastro.operadoras
*
* id_operadora.documento = CPF
*/
id_operadora: string | null;

/** Nome da operadora */
Expand Down
28 changes: 14 additions & 14 deletions src/cnab/dto/cliente-favorecido.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,57 @@ export class SaveClienteFavorecidoDTO {

@ValidateIf(isCreate)
@IsNotEmpty()
cpf_cnpj?: string;
cpf_cnpj?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
cod_banco?: string;
cod_banco?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
agencia?: string;
agencia?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
dv_agencia?: string;
dv_agencia?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
conta_corrente?: string;
conta_corrente?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
dv_conta_corrente?: string;
dv_conta_corrente?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
logradouro?: string;
logradouro?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
numero?: string;
numero?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
complemento?: string;
complemento?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
bairro?: string;
bairro?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
cidade?: string;
cidade?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
cep?: string;
cep?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
complemento_cep?: string;
complemento_cep?: string | null;

@ValidateIf(isCreate)
@IsNotEmpty()
uf?: string;
uf?: string | null;
}
28 changes: 14 additions & 14 deletions src/cnab/entity/cliente-favorecido.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,46 @@ export class ClienteFavorecido extends EntityHelper {
nome: string;

@Column({ type: String, unique: false, nullable: true, length: 14 })
cpf_cnpj: string;
cpf_cnpj: string | null;

@Column({ type: String, unique: false, nullable: true, length: 10 })
cod_banco: string;
cod_banco: string | null;

@Column({ type: String, unique: false, nullable: true, length: 5 })
agencia: string;
agencia: string | null;

@Column({ type: String, unique: false, nullable: true, length: 2 })
dv_agencia: string;
dv_agencia: string | null;

@Column({ type: String, unique: false, nullable: true, length: 12 })
conta_corrente: string;
conta_corrente: string | null;

@Column({ type: String, unique: false, nullable: true, length: 2 })
dv_conta_corrente: string;
dv_conta_corrente: string | null;

@Column({ type: String, unique: false, nullable: true, length: 200 })
logradouro: string;
logradouro: string | null;

@Column({ type: String, unique: false, nullable: true, length: 15 })
numero: string;
numero: string | null;

@Column({ type: String, unique: false, nullable: true, length: 100 })
complemento: string;
complemento: string | null;

@Column({ type: String, unique: false, nullable: true, length: 150 })
bairro: string;
bairro: string | null;

@Column({ type: String, unique: false, nullable: true, length: 150 })
cidade: string;
cidade: string | null;

@Column({ type: String, unique: false, nullable: true, length: 5 })
cep: string;
cep: string | null;

@Column({ type: String, unique: false, nullable: true, length: 3 })
complemento_cep: string;
complemento_cep: string | null;

@Column({ type: String, unique: false, nullable: true, length: 2 })
uf: string;
uf: string | null;

public getLogInfo(showName?: boolean): string {
if (showName === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion src/cnab/entity/transacao.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Transacao extends EntityHelper {
})
vlr_rateio_credito: number;

@Column({ type: Number, unique: false, nullable: true, length: 150 })
@Column({ type: Number, unique: false, nullable: true })
qtde_transacao_rateio_debito: number;

@Column({
Expand Down
18 changes: 9 additions & 9 deletions src/cnab/service/cliente-favorecido.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ export class ClienteFavorecidoService {
dv_agencia: user.getBankAgencyDigit(),
conta_corrente: user.getBankAccount(),
dv_conta_corrente: user.getBankAccountDigit(),
logradouro: '',
numero: '',
complemento: '',
bairro: '',
cidade: '',
cep: '',
complemento_cep: '',
uf: '',
logradouro: null,
numero: null,
complemento: null,
bairro: null,
cidade: null,
cep: null,
complemento_cep: null,
uf: null,
};
await validateDTO(SaveClienteFavorecidoDTO, saveObject);
await this.clienteFavorecidoRepository.save(saveObject);
}
}
}
10 changes: 10 additions & 0 deletions src/cnab/service/transacao.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@ export class TransacaoService {
private bigqueryOrdemPagamentoService: BigqueryOrdemPagamentoService,
) { }

/**
* This task will:
* 1. Update ClienteFavorecidos from Users
* 2. Fetch ordemPgto from this week
* 3. For every id_ordem not in table, add Transacao and
*
* Assumptions:
* 1. Every
*/
public async updateTransacaoFromJae() {
await this.clienteFavorecidoService.updateAllFromUsers();
const ordensPagamento = await this.bigqueryOrdemPagamentoService.getCurrentWeek();
const pagador = await this.pagadorService.getOneByConta(PagadorContaEnum.JAE);
// WIP: idOrdemAux
let idOrdemAux = "";

for (const ordemPagamento of ordensPagamento) {
Expand Down
14 changes: 14 additions & 0 deletions src/database/migrations/1709760544016-AddClienteFavorecido.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class AddClienteFavorecido1709760544016 implements MigrationInterface {
name = 'AddClienteFavorecido1709760544016'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "Cliente_Favorecido" ("id_cliente_favorecido" SERIAL NOT NULL, "nome" character varying(150) NOT NULL, "cpf_cnpj" character varying(14), "cod_banco" character varying(10), "agencia" character varying(5), "dv_agencia" character varying(2), "conta_corrente" character varying(12), "dv_conta_corrente" character varying(2), "logradouro" character varying(200), "numero" character varying(15), "complemento" character varying(100), "bairro" character varying(150), "cidade" character varying(150), "cep" character varying(5), "complemento_cep" character varying(3), "uf" character varying(2), CONSTRAINT "PK_7b620f1eb781f26481c59ef8005" PRIMARY KEY ("id_cliente_favorecido"))`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "Cliente_Favorecido"`);
}

}

0 comments on commit e1a4188

Please sign in to comment.