Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: atualizar para v296 #27

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Pacote de integração com a [API v3 do ERP Bling](https://developer.bling.com.br)
para Javascript/TypeScript. O mais completo existente.

Atualizado com a versão `v295` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-02-28)).
Atualizado com a versão `v296` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-02-28)).

**Atenção**: a versão 5.0.0+ do `bling-erp-api` para Javascript/TypeScript
utiliza a API v3 do Bling. Caso deseja utilizar a API v2 do Bling,
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": "bling-erp-api",
"version": "5.5.0",
"version": "5.6.0",
"description": "Pacote de integração com a API do Bling ERP",
"main": "lib/bling.js",
"directories": {
Expand Down
68 changes: 68 additions & 0 deletions src/entities/contatos/__tests__/find-final-customer.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
export default {
data: {
id: 12345678,
nome: 'Contato',
codigo: 'ASD001',
situacao: 'A' as const,
numeroDocumento: '12345678910',
telefone: '(54) 3333-4444',
celular: '(54) 99999-8888',
fantasia: 'Nome fantasia',
tipo: 'J' as const,
indicadorIe: 1 as const,
ie: '123.456.789.101',
rg: '1234567890',
orgaoEmissor: '1234567890',
email: '[email protected]',
endereco: {
geral: {
endereco: 'R. Olavo Bilac',
cep: '95702-000',
bairro: 'Imigrante',
municipio: 'Bento Gonçalves',
uf: 'RS' as const,
numero: '914',
complemento: 'Sede 101'
},
cobranca: {
endereco: 'R. Olavo Bilac',
cep: '95702-000',
bairro: 'Imigrante',
municipio: 'Bento Gonçalves',
uf: 'RS' as const,
numero: '914',
complemento: 'Sede 101'
}
},
vendedor: {
id: 12345678
},
dadosAdicionais: {
dataNascimento: '1990-08-24',
sexo: 'M' as const,
naturalidade: 'Brasileira'
},
financeiro: {
limiteCredito: 0,
condicaoPagamento: '30',
categoria: {
id: 12345678
}
},
pais: {
nome: 'ESTADOS UNIDOS'
},
tiposContato: [
{
id: 12345678,
descricao: 'Fornecedor'
}
],
pessoasContato: [
{
id: 12345678,
descricao: 'Fornecedor Fulano'
}
]
}
}
18 changes: 18 additions & 0 deletions src/entities/contatos/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Chance } from 'chance'
import { Contatos } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import { ICreateResponse } from '../interfaces/create.interface'
import { IFindFinalCustomerResponse } from '../interfaces/find-final-customer.interface'
import { IFindTypesResponse } from '../interfaces/find-types.interface'
import { IFindResponse } from '../interfaces/find.interface'
import { IGetResponse } from '../interfaces/get.interface'
Expand All @@ -14,6 +15,7 @@ import changeSituationResponse, {
import createResponse, { createRequestBody } from './create-response'
import deleteManyResponse from './delete-many-response'
import deleteResponse from './delete-response'
import findFinalCustomerResponse from './find-final-customer.response'
import findResponse from './find-response'
import findTypesResponse from './find-types-response'
import getResponse from './get-response'
Expand Down Expand Up @@ -137,6 +139,22 @@ describe('Contatos entity', () => {
expect(typingResponseTest).toBe(findTypesResponse)
})

it('should find final customer successfully', async () => {
const spy = jest.spyOn(repository, 'index')
repository.setResponse(findFinalCustomerResponse)

const response = await entity.findFinalCustomer()

expect(spy).toHaveBeenCalledWith({
endpoint: 'contatos/consumidor-final'
})
expect(response).toBe(findFinalCustomerResponse)

const typingResponseTest: IFindFinalCustomerResponse =
findFinalCustomerResponse
expect(typingResponseTest).toBe(findFinalCustomerResponse)
})

it('should change situation successfully', async () => {
const spy = jest.spyOn(repository, 'replace')
const idContato = chance.natural()
Expand Down
15 changes: 15 additions & 0 deletions src/entities/contatos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { ICreateBody, ICreateResponse } from './interfaces/create.interface'
import { IDeleteManyParams } from './interfaces/delete-many.interface'
import { IDeleteParams } from './interfaces/delete.interface'
import { IFindFinalCustomerResponse } from './interfaces/find-final-customer.interface'
import {
IFindTypesParams,
IFindTypesResponse
Expand Down Expand Up @@ -134,6 +135,20 @@ export class Contatos extends Entity {
})
}

/**
* Obtém os dados do contato Consumidor Final.
*
* @returns {Promise<IFindFinalCustomerResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Contatos/get_contatos_consumidor_final
*/
public async findFinalCustomer(): Promise<IFindFinalCustomerResponse> {
return await this.repository.index({
endpoint: 'contatos/consumidor-final'
})
}

/**
* Altera a situação de um contato.
*
Expand Down
64 changes: 64 additions & 0 deletions src/entities/contatos/interfaces/find-final-customer.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import ITipoPessoa from 'src/entities/@shared/types/tipoPessoa.type'
import IUF from 'src/entities/@shared/types/uf.type'
import { IIndicadorIE } from '../types/indicador-ie.type'
import { ISexo } from '../types/sexo.type'
import { ISituacao } from '../types/situacao.type'

export interface IFindFinalCustomerResponse {
data: {
id: number
nome: string
codigo: string
situacao: ISituacao
numeroDocumento: string
telefone: string
celular: string
fantasia: string
tipo: ITipoPessoa
indicadorIe: IIndicadorIE
ie: string
rg: string
orgaoEmissor: string
email: string
endereco: {
geral: {
endereco: string
cep: string
bairro: string
municipio: string
uf: IUF
numero: string
complemento: string
}
cobranca: {
endereco: string
cep: string
bairro: string
municipio: string
uf: IUF
numero: string
complemento: string
}
}
vendedor: { id: number }
dadosAdicionais: {
dataNascimento: string
sexo: ISexo
naturalidade: string
}
financeiro: {
limiteCredito: number
condicaoPagamento: string
categoria: { id: number }
}
pais: { nome: string }
tiposContato: {
id: number
descricao: string
}[]
pessoasContato: {
id: number
descricao: string
}[]
}
}
2 changes: 1 addition & 1 deletion src/entities/contatos/interfaces/find.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface IFindResponse {
naturalidade: string
}
financeiro: {
limiteCredito: 0
limiteCredito: number
condicaoPagamento: string
categoria: { id: number }
}
Expand Down
3 changes: 2 additions & 1 deletion src/entities/vendedores/types/situacao.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
* - `I`: Inativo
* - `S`: Sem movimento
* - `E`: Excluído
* - `T`: Todos
*/
export type ISituacao = 'A' | 'I' | 'S' | 'E'
export type ISituacao = 'A' | 'I' | 'S' | 'E' | 'T'
Loading