diff --git a/README.md b/README.md index db25de0..90c1383 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/package.json b/package.json index 0e66e9e..d736abb 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/entities/contatos/__tests__/find-final-customer.response.ts b/src/entities/contatos/__tests__/find-final-customer.response.ts new file mode 100644 index 0000000..3cccb7e --- /dev/null +++ b/src/entities/contatos/__tests__/find-final-customer.response.ts @@ -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: 'contato@email.com', + 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' + } + ] + } +} diff --git a/src/entities/contatos/__tests__/index.spec.ts b/src/entities/contatos/__tests__/index.spec.ts index 6594cfe..72ce529 100644 --- a/src/entities/contatos/__tests__/index.spec.ts +++ b/src/entities/contatos/__tests__/index.spec.ts @@ -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' @@ -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' @@ -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() diff --git a/src/entities/contatos/index.ts b/src/entities/contatos/index.ts index 3700a6b..16998e0 100644 --- a/src/entities/contatos/index.ts +++ b/src/entities/contatos/index.ts @@ -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 @@ -134,6 +135,20 @@ export class Contatos extends Entity { }) } + /** + * Obtém os dados do contato Consumidor Final. + * + * @returns {Promise} + * @throws {BlingApiException|BlingInternalException} + * + * @see https://developer.bling.com.br/referencia#/Contatos/get_contatos_consumidor_final + */ + public async findFinalCustomer(): Promise { + return await this.repository.index({ + endpoint: 'contatos/consumidor-final' + }) + } + /** * Altera a situação de um contato. * diff --git a/src/entities/contatos/interfaces/find-final-customer.interface.ts b/src/entities/contatos/interfaces/find-final-customer.interface.ts new file mode 100644 index 0000000..0b42725 --- /dev/null +++ b/src/entities/contatos/interfaces/find-final-customer.interface.ts @@ -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 + }[] + } +} diff --git a/src/entities/contatos/interfaces/find.interface.ts b/src/entities/contatos/interfaces/find.interface.ts index 6ce3d8f..55afc59 100644 --- a/src/entities/contatos/interfaces/find.interface.ts +++ b/src/entities/contatos/interfaces/find.interface.ts @@ -54,7 +54,7 @@ export interface IFindResponse { naturalidade: string } financeiro: { - limiteCredito: 0 + limiteCredito: number condicaoPagamento: string categoria: { id: number } } diff --git a/src/entities/vendedores/types/situacao.type.ts b/src/entities/vendedores/types/situacao.type.ts index 7352a0f..6c5e10d 100644 --- a/src/entities/vendedores/types/situacao.type.ts +++ b/src/entities/vendedores/types/situacao.type.ts @@ -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'