diff --git a/README.md b/README.md index 05ea974..59e40d5 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 `v307` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-08-21)). +Atualizado com a versão `v310` da API ([veja o registro de alterações](https://developer.bling.com.br/changelogs#2024-10-02)). **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/src/entities/contasReceber/__tests__/index.spec.ts b/src/entities/contasReceber/__tests__/index.spec.ts index e847cd4..ee6cf14 100644 --- a/src/entities/contasReceber/__tests__/index.spec.ts +++ b/src/entities/contasReceber/__tests__/index.spec.ts @@ -101,7 +101,7 @@ describe('Contas a receber entity', () => { }) expect(spy).toHaveBeenCalledWith({ - endpoint: 'contas/receber/view/bankslips', + endpoint: 'contas/receber/boletos', params: { idOrigem, situations: undefined @@ -153,7 +153,7 @@ describe('Contas a receber entity', () => { const response = await entity.cancelBankSlips(cancelBankSlipRequest) expect(spy).toHaveBeenCalledWith({ - endpoint: 'contas/receber/cancel/bankslips', + endpoint: 'contas/receber/boletos/cancelar', body: cancelBankSlipRequest }) expect(response).toBe(cancelBankSlipsResponse) diff --git a/src/entities/contatos/index.ts b/src/entities/contatos/index.ts index 16998e0..0a5c25e 100644 --- a/src/entities/contatos/index.ts +++ b/src/entities/contatos/index.ts @@ -78,16 +78,20 @@ export class Contatos extends Entity { pesquisa: params?.pesquisa, criterio: params?.criterio, dataInclusaoInicial: this.prepareStringOrDateParam( - params?.dataInclusaoInicial + params?.dataInclusaoInicial, + true ), dataInclusaoFinal: this.prepareStringOrDateParam( - params?.dataInclusaoFinal + params?.dataInclusaoFinal, + true ), dataAlteracaoInicial: this.prepareStringOrDateParam( - params?.dataAlteracaoInicial + params?.dataAlteracaoInicial, + true ), dataAlteracaoFinal: this.prepareStringOrDateParam( - params?.dataAlteracaoFinal + params?.dataAlteracaoFinal, + true ), idTipoContato: params?.idTipoContato, idVendedor: params?.idVendedor, diff --git a/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts b/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts index 61e89a5..09f07f8 100644 --- a/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts +++ b/src/entities/naturezasDeOperacoes/__tests__/index.spec.ts @@ -55,7 +55,7 @@ describe('Naturezas de Operação entity', () => { }) expect(spy).toHaveBeenCalledWith({ - endpoint: `naturezas-operacoes/${idNaturezaOperacao}/calcular-imposto-item`, + endpoint: `naturezas-operacoes/${idNaturezaOperacao}/obter-tributacao`, body: obtainTaxRequestBody }) expect(response).toBe(obtainTaxResponse) diff --git a/src/entities/nfses/__tests__/cancel-response.ts b/src/entities/nfses/__tests__/cancel-response.ts index 7b85954..1cbe559 100644 --- a/src/entities/nfses/__tests__/cancel-response.ts +++ b/src/entities/nfses/__tests__/cancel-response.ts @@ -1 +1,6 @@ export default null + +export const cancelRequest = { + codigoMotivo: 1 as const, + justificativa: "Cancelamento de NFS-e" +} diff --git a/src/entities/nfses/__tests__/get-response.ts b/src/entities/nfses/__tests__/get-response.ts index dacf72a..75af05f 100644 --- a/src/entities/nfses/__tests__/get-response.ts +++ b/src/entities/nfses/__tests__/get-response.ts @@ -5,7 +5,7 @@ export default { numero: '123', numeroRPS: '32', serie: '1', - situacao: 0, + situacao: 0 as const, dataEmissao: '2023-01-12', valor: 100, contato: { diff --git a/src/entities/nfses/__tests__/index.spec.ts b/src/entities/nfses/__tests__/index.spec.ts index 74c5f29..2c937d9 100644 --- a/src/entities/nfses/__tests__/index.spec.ts +++ b/src/entities/nfses/__tests__/index.spec.ts @@ -1,7 +1,7 @@ import { Chance } from 'chance' import { Nfses } from '..' import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' -import cancelResponse from './cancel-response' +import cancelResponse, { cancelRequest } from './cancel-response' import createResponse, { createRequestBody } from './create-response' import deleteResponse from './delete-response' import findResponse from './find-response' @@ -11,6 +11,11 @@ import sendResponse from './send-response' import updateConfigurationsResponse, { updateConfigurationsRequestBody } from './update-configurations-response' +import { IGetResponse } from '../interfaces/get.interface' +import { IFindResponse } from '../interfaces/find.interface' +import { IGetConfigurationsResponse } from '../interfaces/get-configurations.interface' +import { ICreateResponse } from '../interfaces/create.interface' +import { ISendResponse } from '../interfaces/send.interface' const chance = Chance() @@ -39,6 +44,9 @@ describe('NFS-es entity', () => { id: String(idNotaServico) }) expect(response).toBe(deleteResponse) + + const typingResponseTest: null = deleteResponse + expect(typingResponseTest).toBe(deleteResponse) }) it('should get successfully', async () => { @@ -59,6 +67,9 @@ describe('NFS-es entity', () => { } }) expect(response).toBe(getResponse) + + const typingResponseTest: IGetResponse = getResponse + expect(typingResponseTest).toBe(getResponse) }) it('should find successfully', async () => { @@ -73,6 +84,9 @@ describe('NFS-es entity', () => { id: String(idNotaServico) }) expect(response).toBe(findResponse) + + const typingResponseTest: IFindResponse = findResponse + expect(typingResponseTest).toBe(findResponse) }) it('should get configurations successfully', async () => { @@ -85,6 +99,9 @@ describe('NFS-es entity', () => { endpoint: 'nfse/configuracoes' }) expect(response).toBe(getConfigurationsResponse) + + const typingResponseTest: IGetConfigurationsResponse = getConfigurationsResponse + expect(typingResponseTest).toBe(getConfigurationsResponse) }) it('should create successfully', async () => { @@ -98,6 +115,9 @@ describe('NFS-es entity', () => { body: createRequestBody }) expect(response).toBe(createResponse) + + const typingResponseTest: ICreateResponse = createResponse + expect(typingResponseTest).toBe(createResponse) }) it('should send successfully', async () => { @@ -112,6 +132,9 @@ describe('NFS-es entity', () => { body: {} }) expect(response).toBe(sendResponse) + + const typingResponseTest: ISendResponse = sendResponse + expect(typingResponseTest).toBe(sendResponse) }) it('should cancel successfully', async () => { @@ -119,13 +142,16 @@ describe('NFS-es entity', () => { const idNotaServico = chance.natural() repository.setResponse(cancelResponse) - const response = await entity.cancel({ idNotaServico }) + const response = await entity.cancel({ idNotaServico, ...cancelRequest }) expect(spy).toHaveBeenCalledWith({ endpoint: `nfse/${idNotaServico}/cancelar`, - body: {} + body: cancelRequest }) expect(response).toBe(cancelResponse) + + const typingResponseTest: null = cancelResponse + expect(typingResponseTest).toBe(cancelResponse) }) it('should update configurations successfully', async () => { @@ -142,5 +168,8 @@ describe('NFS-es entity', () => { body: updateConfigurationsRequestBody }) expect(response).toBe(updateConfigurationsResponse) + + const typingResponseTest: null = updateConfigurationsResponse + expect(typingResponseTest).toBe(updateConfigurationsResponse) }) }) diff --git a/src/entities/nfses/index.ts b/src/entities/nfses/index.ts index 8835db9..9e9edc3 100644 --- a/src/entities/nfses/index.ts +++ b/src/entities/nfses/index.ts @@ -1,6 +1,6 @@ import { Entity } from '../@shared/entity' import { ISendResponse } from '../nfces/interfaces/send.interface' -import { ICancelParams } from './interfaces/cancel.interface' +import { ICancelBody, ICancelParams } from './interfaces/cancel.interface' import { ICreateBody, ICreateResponse } from './interfaces/create.interface' import { IDeleteParams } from './interfaces/delete.interface' import { IFindParams, IFindResponse } from './interfaces/find.interface' @@ -127,17 +127,18 @@ export class Nfses extends Entity { /** * Cancela uma nota de serviço. * - * @param {ICancelParams} params Os parâmetros de envio. + * @param {ICancelParams & ICancelBody} params Os parâmetros de envio. * * @returns {Promise} * @throws {BlingApiException|BlingInternalException} * * @see https://developer.bling.com.br/referencia#/Notas%20Fiscais%20de%20Servi%C3%A7o%20Eletr%C3%B4nicas/post_nfse__idNotaServico__cancelar */ - public async cancel(params: ICancelParams): Promise { + public async cancel(params: ICancelParams & ICancelBody): Promise { + const { idNotaServico, ...body } = params return await this.repository.store({ - endpoint: `nfse/${params.idNotaServico}/cancelar`, - body: {} + endpoint: `nfse/${idNotaServico}/cancelar`, + body }) } diff --git a/src/entities/nfses/interfaces/cancel.interface.ts b/src/entities/nfses/interfaces/cancel.interface.ts index b55da50..e134a87 100644 --- a/src/entities/nfses/interfaces/cancel.interface.ts +++ b/src/entities/nfses/interfaces/cancel.interface.ts @@ -1,6 +1,13 @@ +import { ICancelarCodigoMotivo } from "../types/cancelar-codigo-motivo.type" + export interface ICancelParams { /** * ID da nota de serviço */ idNotaServico: number } + +export interface ICancelBody { + codigoMotivo?: ICancelarCodigoMotivo + justificativa?: string +} diff --git a/src/entities/nfses/types/cancelar-codigo-motivo.type.ts b/src/entities/nfses/types/cancelar-codigo-motivo.type.ts new file mode 100644 index 0000000..05ad763 --- /dev/null +++ b/src/entities/nfses/types/cancelar-codigo-motivo.type.ts @@ -0,0 +1,9 @@ +/** + * - `1`: Erro na Emissão + * - `2`: Serviço não Prestado + * - `9`: Outros + */ +export type ICancelarCodigoMotivo = + | 1 + | 2 + | 9 diff --git a/src/entities/pedidosVendas/index.ts b/src/entities/pedidosVendas/index.ts index 8eef756..432c7f4 100644 --- a/src/entities/pedidosVendas/index.ts +++ b/src/entities/pedidosVendas/index.ts @@ -91,10 +91,12 @@ export class PedidosVendas extends Entity { dataInicial: this.prepareStringOrDateParam(params?.dataInicial), dataFinal: this.prepareStringOrDateParam(params?.dataFinal), dataAlteracaoInicial: this.prepareStringOrDateParam( - params?.dataAlteracaoInicial + params?.dataAlteracaoInicial, + true ), dataAlteracaoFinal: this.prepareStringOrDateParam( - params?.dataAlteracaoFinal + params?.dataAlteracaoFinal, + true ), dataPrevistaInicial: this.prepareStringOrDateParam( params?.dataPrevistaInicial