-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: nova release (#29)
Showing
109 changed files
with
3,397 additions
and
895 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
"aliquota", | ||
"Amazônia", | ||
"autoload", | ||
"boletos", | ||
"borderô", | ||
"Borderos", | ||
"borderôs", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 11 additions & 5 deletions
16
src/entities/contasReceber/__tests__/cancel-bank-slips-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
export default null | ||
|
||
export const cancelBankSlipRequest = { | ||
type2FA: 1, | ||
code2FA: '111111', | ||
idOrigem: 16853468718, | ||
idDuplicata: 16853468712, | ||
reason: 'motivo' | ||
autenticacao: { | ||
tipo: 1 as const, | ||
codigo: "111111" | ||
}, | ||
origem: { | ||
id: 5436875653 | ||
}, | ||
conta: { | ||
id: 6423836115 | ||
}, | ||
motivo: "Cancelado por força maior" | ||
} |
24 changes: 12 additions & 12 deletions
24
src/entities/contasReceber/__tests__/get-bank-slips-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
export default { | ||
numberSale: '149', | ||
numberNF: '000001', | ||
amountAccounts: 1, | ||
amountValuesAccounts: 111.2, | ||
haveAccountWithIntegration: true, | ||
accounts: [ | ||
venda: { | ||
numero: "123" | ||
}, | ||
notaFiscal: { | ||
numero: "000001" | ||
}, | ||
valorTotal: 111.2, | ||
contas: [ | ||
{ | ||
id: 1328793273, | ||
idExternal: 'BWbXB', | ||
dueDate: '2023-09-12', | ||
value: 111.2, | ||
situation: 'aberto' as const, | ||
iconSituation: 'aberto', | ||
descriptionSituation: 'Em aberto' | ||
numeroExterno: "BWbXB", | ||
vencimento: "2023-09-12", | ||
valor: 111.2, | ||
situacao: 1 as const | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 14 additions & 36 deletions
50
src/entities/contasReceber/interfaces/cancel-bank-slips.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,15 @@ | ||
interface ContasReceberBankSlipsCancelUnicoDTO { | ||
type2FA: number | ||
code2FA: string | ||
/** | ||
* caso for cancelar uma conta sem idOrigem enviar o valor `0` | ||
*/ | ||
idOrigem: number | ||
idDuplicata: number | ||
reason: string | ||
import { ITipoAutenticacao } from "../types/tipo-autenticacao.type" | ||
|
||
export interface ICancelBankSlipsBody { | ||
autenticacao?: { | ||
tipo: ITipoAutenticacao | ||
codigo: string | ||
}, | ||
origem?: { | ||
id: number | ||
}, | ||
conta?: { | ||
id: number | ||
}, | ||
motivo: string | ||
} | ||
|
||
interface ContasReceberBankSlipsCancelTodosDTO { | ||
type2FA: number | ||
code2FA: string | ||
idOrigem: number | ||
reason: string | ||
} | ||
|
||
interface ContasReceberBankSlipsCancelUnicoSem2FADTO { | ||
/** | ||
* caso for cancelar uma conta sem idOrigem enviar o valor `0` | ||
*/ | ||
idOrigem: number | ||
idDuplicata: number | ||
reason: string | ||
} | ||
|
||
interface ContasReceberBankSlipsCancelTodosSem2FADTO { | ||
idOrigem: number | ||
reason: string | ||
} | ||
|
||
export type ICancelBankSlipsBody = | ||
| ContasReceberBankSlipsCancelUnicoDTO | ||
| ContasReceberBankSlipsCancelTodosDTO | ||
| ContasReceberBankSlipsCancelUnicoSem2FADTO | ||
| ContasReceberBankSlipsCancelTodosSem2FADTO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions
28
src/entities/contasReceber/interfaces/get-bank-slips.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { ISituacaoString } from '../types/situacao.type' | ||
import { ISituacao } from '../types/situacao.type' | ||
|
||
export interface IGetBankSlipsParams { | ||
idOrigem: number | ||
situations?: ISituacaoString[] | ||
situacoes?: ISituacao[] | ||
} | ||
|
||
export interface IGetBankSlipsResponse { | ||
numberSale: string | ||
numberNF: string | ||
amountAccounts: number | ||
amountValuesAccounts: number | ||
haveAccountWithIntegration: boolean | ||
accounts: { | ||
venda: { | ||
numero: string | ||
}, | ||
notaFiscal: { | ||
numero: string | ||
}, | ||
valorTotal: number | ||
contas: { | ||
id: number | ||
idExternal: string | ||
dueDate: string | ||
value: number | ||
situation: ISituacaoString | ||
iconSituation: string | ||
descriptionSituation: string | ||
numeroExterno: string | ||
vencimento: string | ||
valor: number | ||
situacao: ISituacao | ||
}[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* - `1`: Código de autenticação por dois fatores | ||
* - `4`: Senha de 6 dígitos do app Bling Conta | ||
*/ | ||
export type ITipoAutenticacao = 1 | 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export default { | ||
data: { | ||
nome: 'Empresa Teste LTDA', | ||
cnpj: '12.345.657/8910-11', | ||
email: 'empresa@email.com' | ||
id: "436c56a5679921f5f13a3d6433561773", | ||
nome: "Empresa Teste LTDA", | ||
cnpj: "12.345.657/8910-11", | ||
email: "empresa@email.com", | ||
dataContrato: "2024-12-31" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export interface IMeResponse { | ||
data: { | ||
id: string | ||
nome: string | ||
cnpj: string | ||
email: string | ||
dataContrato: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/entities/gruposDeProdutos/__tests__/create-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const createRequestBody = { | ||
nome: "Grupo 1", | ||
grupoProdutoPai: { | ||
id: 123456 | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/entities/gruposDeProdutos/__tests__/delete-many-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export default { | ||
data: { | ||
alertas: [ | ||
{ | ||
error: { | ||
type: "VALIDATION_ERROR", | ||
message: "Não foi possível salvar a venda", | ||
description: "A venda não pode ser salva, pois ocorreram problemas em sua validação.", | ||
fields: [ | ||
{ | ||
code: 49, | ||
msg: "Uma ou mais parcelas da venda possuem erros de validação", | ||
element: "parcelas", | ||
namespace: "VENDAS", | ||
collection: [ | ||
{ | ||
index: 1, | ||
code: 12, | ||
msg: "Id da forma de pagamento inválido.", | ||
element: "formaPagamento", | ||
namespace: "VENDAS" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
data: { | ||
id: 123456, | ||
nome: "Grupo 1", | ||
grupoProdutoPai: { | ||
id: 123456, | ||
nome: "Grupo 1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default { | ||
data: [ | ||
{ | ||
id: 123456, | ||
nome: "Grupo 1", | ||
grupoProdutoPai: { | ||
id: 123456, | ||
nome: "Grupo 1" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { Chance } from 'chance' | ||
import { GruposDeProdutos } from '..' | ||
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' | ||
import { ICreateResponse } from '../interfaces/create.interface' | ||
import { IDeleteManyResponse } from '../interfaces/delete-many.interface' | ||
import { IFindResponse } from '../interfaces/find.interface' | ||
import { IGetResponse } from '../interfaces/get.interface' | ||
import createResponse, { createRequestBody } from './create-response' | ||
import deleteManyResponse from './delete-many-response' | ||
import deleteResponse from './delete-response' | ||
import findResponse from './find-response' | ||
import getResponse from './get-response' | ||
import updateResponse, { updateRequestBody } from './update-response' | ||
|
||
const chance = Chance() | ||
|
||
describe('GruposDeProdutos entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: GruposDeProdutos | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new GruposDeProdutos(repository) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should delete many successfully', async () => { | ||
const idsGruposProdutos: number[] = [] | ||
for (let i = 0; i < chance.natural({ min: 1, max: 5 }); i++) { | ||
idsGruposProdutos.push(chance.natural()) | ||
} | ||
const spy = jest.spyOn(repository, 'destroy') | ||
repository.setResponse(deleteManyResponse) | ||
|
||
const response = await entity.deleteMany({ idsGruposProdutos }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'grupos-produtos', | ||
id: '', | ||
params: { idsGruposProdutos } | ||
}) | ||
expect(response).toBe(deleteManyResponse) | ||
|
||
const typingResponseTest: IDeleteManyResponse = deleteManyResponse | ||
expect(typingResponseTest).toBe(deleteManyResponse) | ||
}) | ||
|
||
it('should delete successfully', async () => { | ||
const idGrupoProduto = chance.natural() | ||
const spy = jest.spyOn(repository, 'destroy') | ||
repository.setResponse(deleteResponse) | ||
|
||
const response = await entity.delete({ idGrupoProduto }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'grupos-produtos', | ||
id: String(idGrupoProduto) | ||
}) | ||
expect(response).toBe(deleteResponse) | ||
|
||
const typingResponseTest: null = deleteResponse | ||
expect(typingResponseTest).toBe(deleteResponse) | ||
}) | ||
|
||
it('should get successfully', async () => { | ||
const spy = jest.spyOn(repository, 'index') | ||
repository.setResponse(getResponse) | ||
|
||
const response = await entity.get() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'grupos-produtos', | ||
params: { | ||
nome: undefined, | ||
nomePai: undefined, | ||
pagina: undefined, | ||
limite: undefined | ||
} | ||
}) | ||
expect(response).toBe(getResponse) | ||
|
||
const typingResponseTest: IGetResponse = getResponse | ||
expect(typingResponseTest).toBe(getResponse) | ||
}) | ||
|
||
it('should find successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idGrupoProduto = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idGrupoProduto }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'grupos-produtos', | ||
id: String(idGrupoProduto) | ||
}) | ||
expect(response).toBe(findResponse) | ||
|
||
const typingResponseTest: IFindResponse = findResponse | ||
expect(typingResponseTest).toBe(findResponse) | ||
}) | ||
|
||
it('should create successfully', async () => { | ||
const spy = jest.spyOn(repository, 'store') | ||
repository.setResponse(createResponse) | ||
|
||
const response = await entity.create(createRequestBody) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'grupos-produtos', | ||
body: createRequestBody | ||
}) | ||
expect(response).toBe(createResponse) | ||
|
||
const typingResponseTest: ICreateResponse = createResponse | ||
expect(typingResponseTest).toBe(createResponse) | ||
}) | ||
|
||
it('should update successfully', async () => { | ||
const spy = jest.spyOn(repository, 'replace') | ||
const idGrupoProduto = chance.natural() | ||
repository.setResponse(updateResponse) | ||
|
||
const response = await entity.update({ | ||
idGrupoProduto, | ||
...updateRequestBody | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'grupos-produtos', | ||
id: String(idGrupoProduto), | ||
body: updateRequestBody | ||
}) | ||
expect(response).toBe(updateResponse) | ||
|
||
const typingResponseTest: null = updateResponse | ||
expect(typingResponseTest).toBe(updateResponse) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default null | ||
|
||
export const updateRequestBody = { | ||
nome: "Grupo 1", | ||
grupoProdutoPai: { | ||
id: 123456 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { Entity } from '../@shared/entity' | ||
import { ICreateBody, ICreateResponse } from './interfaces/create.interface' | ||
import { | ||
IDeleteManyParams, | ||
IDeleteManyResponse | ||
} from './interfaces/delete-many.interface' | ||
import { IDeleteParams } from './interfaces/delete.interface' | ||
import { IFindParams, IFindResponse } from './interfaces/find.interface' | ||
import { IGetParams, IGetResponse } from './interfaces/get.interface' | ||
import { | ||
IUpdateBody, | ||
IUpdateParams | ||
} from './interfaces/update.interface' | ||
|
||
/** | ||
* Entidade para interação com Grupos de Produtos. | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Grupos%20de%20Produtos | ||
*/ | ||
export class GruposDeProdutos extends Entity { | ||
/** | ||
* Remove múltiplos grupos de produtos. | ||
* | ||
* @param {IDeleteManyParams} params Parâmetros da remoção. | ||
* | ||
* @returns {Promise<IDeleteManyResponse>} Não há retorno. | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Grupos%20de%20Produtos/delete_grupos_produtos | ||
*/ | ||
public async deleteMany( | ||
params: IDeleteManyParams | ||
): Promise<IDeleteManyResponse> { | ||
return await this.repository.destroy({ | ||
endpoint: 'grupos-produtos', | ||
id: '', | ||
params: { idsGruposProdutos: params.idsGruposProdutos } | ||
}) | ||
} | ||
|
||
/** | ||
* Remove um grupo de produtos. | ||
* | ||
* @param {IDeleteParams} params Parâmetros da remoção. | ||
* | ||
* @returns {Promise<null>} Não há retorno. | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Grupos%20de%20Produtos/delete_grupos_produtos__idGrupoProduto_ | ||
*/ | ||
public async delete(params: IDeleteParams): Promise<null> { | ||
return await this.repository.destroy({ | ||
endpoint: 'grupos-produtos', | ||
id: String(params.idGrupoProduto) | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém grupos de produtos. | ||
* | ||
* @param {IGetParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IGetResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/GruposDeProdutos/get_produtos | ||
*/ | ||
public async get(params?: IGetParams): Promise<IGetResponse> { | ||
return await this.repository.index({ | ||
endpoint: 'grupos-produtos', | ||
params: { | ||
nome: params?.nome, | ||
nomePai: params?.nomePai, | ||
pagina: params?.pagina, | ||
limite: params?.limite, | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém um grupo de produtos. | ||
* | ||
* @param {IFindParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IFindResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Grupos%20de%20Produtos/get_grupos_produtos__idGrupoProduto_ | ||
*/ | ||
public async find(params: IFindParams): Promise<IFindResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'grupos-produtos', | ||
id: String(params.idGrupoProduto) | ||
}) | ||
} | ||
|
||
/** | ||
* Cria um grupo de produtos. | ||
* | ||
* @param {ICreateBody} body O conteúdo para a criação. | ||
* | ||
* @returns {Promise<ICreateResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Grupos%20de%20Produtos/post_grupos_produtos | ||
*/ | ||
public async create(body: ICreateBody): Promise<ICreateResponse> { | ||
return await this.repository.store({ | ||
endpoint: 'grupos-produtos', | ||
body | ||
}) | ||
} | ||
|
||
/** | ||
* Altera um grupo de produtos. | ||
* | ||
* @param {IUpdateParams & IUpdateBody} params Os parâmetros da atualização. | ||
* | ||
* @return {Promise<null>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Grupos%20de%20Produtos/put_grupos_produtos__idGrupoProduto_ | ||
*/ | ||
public async update( | ||
params: IUpdateParams & IUpdateBody | ||
): Promise<null> { | ||
const { idGrupoProduto, ...body } = params | ||
|
||
return await this.repository.replace({ | ||
endpoint: 'grupos-produtos', | ||
id: String(idGrupoProduto), | ||
body | ||
}) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/entities/gruposDeProdutos/interfaces/create.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface ICreateBody { | ||
nome: string | ||
grupoProdutoPai: { | ||
id: number | ||
} | ||
} | ||
|
||
export interface ICreateResponse { | ||
data: { | ||
id: number | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/entities/gruposDeProdutos/interfaces/delete-many.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IDefaultErrorResponse } from 'src/entities/@shared/interfaces/error.interface' | ||
|
||
export interface IDeleteManyParams { | ||
/** | ||
* IDs dos grupos de produtos | ||
*/ | ||
idsGruposProdutos: number[] | ||
} | ||
|
||
export interface IDeleteManyResponse { | ||
data: { | ||
alertas?: IDefaultErrorResponse[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface IDeleteParams { | ||
/** | ||
* ID do grupo de produto | ||
*/ | ||
idGrupoProduto: number | ||
} |
24 changes: 24 additions & 0 deletions
24
src/entities/gruposDeProdutos/interfaces/find.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export interface IFindParams { | ||
/** | ||
* ID do grupo de produto | ||
*/ | ||
idGrupoProduto: number | ||
} | ||
|
||
interface GruposProdutosDadosDTO { | ||
id?: number | ||
nome: string | ||
grupoProdutoPai?: { | ||
id: number | ||
nome?: string | ||
} | ||
} | ||
|
||
interface GruposProdutosGrupoProdutoPaiDTO { | ||
id: number | ||
nome?: string | ||
} | ||
|
||
export interface IFindResponse { | ||
data: GruposProdutosDadosDTO | GruposProdutosGrupoProdutoPaiDTO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export interface IGetParams { | ||
/** | ||
* O nome do grupo | ||
*/ | ||
nome?: string | ||
/** | ||
* O nome do grupo pai | ||
*/ | ||
nomePai?: string | ||
/** | ||
* N° da página da listagem | ||
*/ | ||
pagina?: number | ||
/** | ||
* Quantidade de registros que devem ser exibidos por página | ||
*/ | ||
limite?: number | ||
} | ||
|
||
export interface IGetResponse { | ||
data: { | ||
id?: number | ||
nome: string | ||
grupoProdutoPai?: { | ||
id: number | ||
nome?: string | ||
} | ||
}[] | ||
} |
13 changes: 13 additions & 0 deletions
13
src/entities/gruposDeProdutos/interfaces/update.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface IUpdateParams { | ||
/** | ||
* ID do grupo de produto | ||
*/ | ||
idGrupoProduto: number | ||
} | ||
|
||
export interface IUpdateBody { | ||
nome: string | ||
grupoProdutoPai: { | ||
id: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* - `1`: Outro(s) | ||
* - `2`: Volume(s) | ||
* - `3`: Unidade(s) | ||
* - `4`: Caixa(s) | ||
* - `5`: Pacote(s) | ||
* - `6`: Envelope(s) | ||
* - `7`: Pallet(s) | ||
* - `8`: Saco(s) | ||
*/ | ||
export type IEspecie = | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* - `1`: Outro(s) | ||
* - `2`: Volume(s) | ||
* - `3`: Unidade(s) | ||
* - `4`: Caixa(s) | ||
* - `5`: Pacote(s) | ||
* - `6`: Envelope(s) | ||
* - `7`: Pallet(s) | ||
* - `8`: Saco(s) | ||
*/ | ||
export type IEspecie = | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export default null | ||
|
||
export const cancelRequest = { | ||
codigoMotivo: 1 as const, | ||
justificativa: "Cancelamento de NFS-e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* - `1`: Erro na Emissão | ||
* - `2`: Serviço não Prestado | ||
* - `9`: Outros | ||
*/ | ||
export type ICancelarCodigoMotivo = | ||
| 1 | ||
| 2 | ||
| 9 |
8 changes: 8 additions & 0 deletions
8
src/entities/ordensDeProducao/__tests__/change-situation-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default null | ||
|
||
export const changeSituationRequest = { | ||
idSituacao: 12345678, | ||
quantidade: 1, | ||
observacoes: "Observação", | ||
considerarPerdas: true | ||
} |
30 changes: 30 additions & 0 deletions
30
src/entities/ordensDeProducao/__tests__/create-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const createRequestBody = { | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678 | ||
}, | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678 | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
observacoes: "Observações" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export default { | ||
id: 12345678, | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678, | ||
valor: 1, | ||
nome: "Em aberto" | ||
}, | ||
vendas: [ | ||
{ | ||
numero: 12345678, | ||
contato: { | ||
id: 12345678, | ||
nome: "João da Silva" | ||
} | ||
} | ||
], | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678, | ||
nome: "Nome do produto", | ||
codigo: "Código do produto" | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
observacoes: "Observações" | ||
} |
21 changes: 21 additions & 0 deletions
21
src/entities/ordensDeProducao/__tests__/generate-over-demand-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export default { | ||
data: [ | ||
{ | ||
id: 12345678, | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678, | ||
nome: "Nome do produto", | ||
codigo: "Código do produto" | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export default { | ||
data: [ | ||
{ | ||
id: 12345678, | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678, | ||
valor: 1, | ||
nome: "Em aberto" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
import { Chance } from 'chance' | ||
import { OrdensDeProducao } from '..' | ||
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository' | ||
import { ICreateResponse } from '../interfaces/create.interface' | ||
import { IFindResponse } from '../interfaces/find.interface' | ||
import { IGetResponse } from '../interfaces/get.interface' | ||
import changeSituationResponse, { | ||
changeSituationRequest | ||
} from './change-situation-response' | ||
import createResponse, { createRequestBody } from './create-response' | ||
import deleteResponse from './delete-response' | ||
import findResponse from './find-response' | ||
import getResponse from './get-response' | ||
import updateResponse, { updateRequestBody } from './update-response' | ||
import generateOverDemandResponse from './generate-over-demand-response' | ||
import { IGenerateOverDemandResponse } from '../interfaces/generate-over-demand.interface' | ||
|
||
const chance = Chance() | ||
|
||
describe('OrdensDeProducao entity', () => { | ||
let repository: InMemoryBlingRepository | ||
let entity: OrdensDeProducao | ||
|
||
beforeEach(() => { | ||
repository = new InMemoryBlingRepository() | ||
entity = new OrdensDeProducao(repository) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
it('should delete successfully', async () => { | ||
const idOrdemProducao = chance.natural() | ||
const spy = jest.spyOn(repository, 'destroy') | ||
repository.setResponse(deleteResponse) | ||
|
||
const response = await entity.delete({ idOrdemProducao }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao) | ||
}) | ||
expect(response).toBe(deleteResponse) | ||
|
||
const typingResponseTest: null = deleteResponse | ||
expect(typingResponseTest).toBe(deleteResponse) | ||
}) | ||
|
||
it('should get successfully', async () => { | ||
const spy = jest.spyOn(repository, 'index') | ||
repository.setResponse(getResponse) | ||
|
||
const response = await entity.get() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
params: { | ||
limite: undefined, | ||
pagina: undefined, | ||
idsSituacoes: undefined | ||
} | ||
}) | ||
expect(response).toBe(getResponse) | ||
|
||
const typingResponseTest: IGetResponse = getResponse | ||
expect(typingResponseTest).toBe(getResponse) | ||
}) | ||
|
||
it('should find successfully', async () => { | ||
const spy = jest.spyOn(repository, 'show') | ||
const idOrdemProducao = chance.natural() | ||
repository.setResponse(findResponse) | ||
|
||
const response = await entity.find({ idOrdemProducao }) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao) | ||
}) | ||
expect(response).toBe(findResponse) | ||
|
||
const typingResponseTest: IFindResponse = findResponse | ||
expect(typingResponseTest).toBe(findResponse) | ||
}) | ||
|
||
it('should create successfully', async () => { | ||
const spy = jest.spyOn(repository, 'store') | ||
repository.setResponse(createResponse) | ||
|
||
const response = await entity.create(createRequestBody) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
body: createRequestBody | ||
}) | ||
expect(response).toBe(createResponse) | ||
|
||
const typingResponseTest: ICreateResponse = createResponse | ||
expect(typingResponseTest).toBe(createResponse) | ||
}) | ||
|
||
it('should generate over demand successfully', async () => { | ||
const spy = jest.spyOn(repository, 'store') | ||
repository.setResponse(generateOverDemandResponse) | ||
|
||
const response = await entity.generateOverDemand() | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao/gerar-sob-demanda', | ||
body: {} | ||
}) | ||
expect(response).toBe(generateOverDemandResponse) | ||
|
||
const typingResponseTest: IGenerateOverDemandResponse = generateOverDemandResponse | ||
expect(typingResponseTest).toBe(generateOverDemandResponse) | ||
}) | ||
|
||
it('should update successfully', async () => { | ||
const spy = jest.spyOn(repository, 'replace') | ||
const idOrdemProducao = chance.natural() | ||
repository.setResponse(updateResponse) | ||
|
||
const response = await entity.update({ | ||
idOrdemProducao, | ||
...updateRequestBody | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao), | ||
body: updateRequestBody | ||
}) | ||
expect(response).toBe(updateResponse) | ||
|
||
const typingResponseTest: null = updateResponse | ||
expect(typingResponseTest).toBe(updateResponse) | ||
}) | ||
|
||
it('should change situation successfully', async () => { | ||
const spy = jest.spyOn(repository, 'update') | ||
const idOrdemProducao = chance.natural() | ||
repository.setResponse(changeSituationResponse) | ||
|
||
const response = await entity.changeSituation({ | ||
idOrdemProducao, | ||
...changeSituationRequest | ||
}) | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
endpoint: 'ordens-producao', | ||
id: `${idOrdemProducao}/situacoes`, | ||
body: changeSituationRequest | ||
}) | ||
expect(response).toBe(changeSituationResponse) | ||
|
||
const typingResponseTest: null = changeSituationResponse | ||
expect(typingResponseTest).toBe(changeSituationResponse) | ||
}) | ||
}) |
26 changes: 26 additions & 0 deletions
26
src/entities/ordensDeProducao/__tests__/update-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export default null | ||
|
||
export const updateRequestBody = { | ||
dataPrevisaoInicio: "2021-01-01", | ||
dataPrevisaoFinal: "2021-01-01", | ||
dataInicio: "2021-01-01", | ||
dataFim: "2021-01-01", | ||
numero: 12345678, | ||
responsavel: "Responsável pela ordem de produção", | ||
deposito: { | ||
idDestino: 12345678, | ||
idOrigem: 12345678 | ||
}, | ||
situacao: { | ||
id: 12345678 | ||
}, | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678 | ||
}, | ||
quantidade: 1 | ||
} | ||
], | ||
observacoes: "Observações" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { Entity } from '../@shared/entity' | ||
import { IChangeSituationBody, IChangeSituationParams } from './interfaces/change-situation.interface' | ||
import { ICreateBody, ICreateResponse } from './interfaces/create.interface' | ||
import { IDeleteParams } from './interfaces/delete.interface' | ||
import { IFindParams, IFindResponse } from './interfaces/find.interface' | ||
import { IGenerateOverDemandResponse } from './interfaces/generate-over-demand.interface' | ||
import { IGetParams, IGetResponse } from './interfaces/get.interface' | ||
import { IUpdateBody, IUpdateParams } from './interfaces/update.interface' | ||
|
||
/** | ||
* Entidade para interação com Ordens de Produção. | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o | ||
*/ | ||
export class OrdensDeProducao extends Entity { | ||
/** | ||
* Remove uma ordem de produção. | ||
* | ||
* @param {IDeleteParams} params Parâmetros da remoção. | ||
* | ||
* @returns {Promise<null>} Não há retorno. | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/delete_ordens_producao__idOrdemProducao_ | ||
*/ | ||
public async delete(params: IDeleteParams): Promise<null> { | ||
return await this.repository.destroy({ | ||
endpoint: 'ordens-producao', | ||
id: String(params.idOrdemProducao) | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém ordens de produção. | ||
* | ||
* @param {IGetParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IGetResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/get_ordens_producao | ||
*/ | ||
public async get(params?: IGetParams): Promise<IGetResponse> { | ||
return await this.repository.index({ | ||
endpoint: 'ordens-producao', | ||
params: { | ||
pagina: params?.pagina, | ||
limite: params?.limite, | ||
idsSituacoes: params?.idsSituacoes | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Obtém uma ordem de produção. | ||
* | ||
* @param {IFindParams} params Parâmetros da busca. | ||
* | ||
* @returns {Promise<IFindResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/get_ordens_producao__idOrdemProducao_ | ||
*/ | ||
public async find(params: IFindParams): Promise<IFindResponse> { | ||
return await this.repository.show({ | ||
endpoint: 'ordens-producao', | ||
id: String(params.idOrdemProducao) | ||
}) | ||
} | ||
|
||
/** | ||
* Cria uma ordem de produção. | ||
* | ||
* @param {ICreateBody} body O conteúdo para a criação. | ||
* | ||
* @returns {Promise<ICreateResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/post_ordens_producao | ||
*/ | ||
public async create(body: ICreateBody): Promise<ICreateResponse> { | ||
return await this.repository.store({ | ||
endpoint: 'ordens-producao', | ||
body | ||
}) | ||
} | ||
|
||
/** | ||
* Gera ordens de produção sob demanda. | ||
* | ||
* @returns {Promise<IGenerateOverDemandResponse>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/post_ordens_producao_gerar_sob_demanda | ||
*/ | ||
public async generateOverDemand(): Promise<IGenerateOverDemandResponse> { | ||
return await this.repository.store({ | ||
endpoint: 'ordens-producao/gerar-sob-demanda', | ||
body: {} | ||
}) | ||
} | ||
|
||
/** | ||
* Altera uma ordem de produção. | ||
* | ||
* @param {IUpdateParams & IUpdateBody} params Os parâmetros da atualização. | ||
* | ||
* @return {Promise<null>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Ordens%20de%20Produ%C3%A7%C3%A3o/put_ordens_producao__idOrdemProducao_ | ||
*/ | ||
public async update( | ||
params: IUpdateParams & IUpdateBody | ||
): Promise<null> { | ||
const { idOrdemProducao, ...body } = params | ||
|
||
return await this.repository.replace({ | ||
endpoint: 'ordens-producao', | ||
id: String(idOrdemProducao), | ||
body | ||
}) | ||
} | ||
/** | ||
* Altera a situação de uma ordem de produção. | ||
* | ||
* @param {IChangeSituationParams & IChangeSituationBody} params Parâmetros da alteração. | ||
* | ||
* @returns {Promise<null>} | ||
* @throws {BlingApiException|BlingInternalException} | ||
* | ||
* @see https://developer.bling.com.br/referencia#/Produtos/.idOrdemProducao__situacoes | ||
*/ | ||
public async changeSituation( | ||
params: IChangeSituationParams & IChangeSituationBody | ||
): Promise<null> { | ||
const { idOrdemProducao, ...body } = params | ||
return await this.repository.update({ | ||
endpoint: 'ordens-producao', | ||
id: `${idOrdemProducao}/situacoes`, | ||
body | ||
}) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/entities/ordensDeProducao/interfaces/change-situation.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface IChangeSituationParams { | ||
/** | ||
* ID da ordem de produção | ||
*/ | ||
idOrdemProducao: number | ||
} | ||
|
||
export interface IChangeSituationBody { | ||
idSituacao: number | ||
quantidade?: number | ||
observacoes?: string | ||
considerarPerdas?: boolean | ||
} |
29 changes: 29 additions & 0 deletions
29
src/entities/ordensDeProducao/interfaces/create.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export interface ICreateBody { | ||
dataPrevisaoInicio?: string | ||
dataPrevisaoFinal?: string | ||
dataInicio?: string | ||
dataFim?: string | ||
numero: number | ||
responsavel?: string | ||
deposito: { | ||
idDestino?: number | ||
idOrigem?: number | ||
} | ||
situacao: { | ||
id: number | ||
} | ||
itens?: { | ||
produto?: { | ||
id: number | ||
} | ||
quantidade?: number | ||
}[] | ||
|
||
observacoes?: string | ||
} | ||
|
||
export interface ICreateResponse { | ||
data?: { | ||
id: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface IDeleteParams { | ||
/** | ||
* ID da ordem de produção | ||
*/ | ||
idOrdemProducao: number | ||
} |
41 changes: 41 additions & 0 deletions
41
src/entities/ordensDeProducao/interfaces/find.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export interface IFindParams { | ||
/** | ||
* ID da ordem de produção | ||
*/ | ||
idOrdemProducao: number | ||
} | ||
|
||
export interface IFindResponse { | ||
id: number | ||
dataPrevisaoInicio?: string | ||
dataPrevisaoFinal?: string | ||
dataInicio?: string | ||
dataFim?: string | ||
numero: number | ||
responsavel?: string | ||
deposito: { | ||
idDestino?: number | ||
idOrigem?: number | ||
} | ||
situacao: { | ||
id: number | ||
valor: number | ||
nome: string | ||
} | ||
vendas?: { | ||
numero?: number | ||
contato?: { | ||
id?: number | ||
nome?: string | ||
} | ||
}[] | ||
itens?: { | ||
produto?: { | ||
id: number | ||
nome?: string | ||
codigo?: string | ||
} | ||
quantidade?: number | ||
}[] | ||
observacoes?: string | ||
} |
18 changes: 18 additions & 0 deletions
18
src/entities/ordensDeProducao/interfaces/generate-over-demand.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export interface IGenerateOverDemandResponse { | ||
data?: { | ||
id?: number | ||
itens?: { | ||
produto?: { | ||
id: number | ||
nome?: string | ||
codigo?: string | ||
} | ||
quantidade?: number | ||
}[] | ||
|
||
deposito?: { | ||
idDestino?: number | ||
idOrigem?: number | ||
} | ||
}[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export interface IGetParams { | ||
/** | ||
* N° da página da listagem | ||
*/ | ||
pagina?: number | ||
/** | ||
* Quantidade de registros que devem ser exibidos por página | ||
*/ | ||
limite?: number | ||
/** | ||
* IDs das situações | ||
*/ | ||
idsSituacoes?: number[] | ||
} | ||
|
||
export interface IGetResponse { | ||
data: { | ||
id: number | ||
dataPrevisaoInicio?: string | ||
dataPrevisaoFinal?: string | ||
dataInicio?: string | ||
dataFim?: string | ||
numero: number | ||
responsavel?: string | ||
deposito: { | ||
idDestino?: number | ||
idOrigem?: number | ||
} | ||
situacao: { | ||
id: number | ||
valor: number | ||
nome: string | ||
} | ||
}[] | ||
} |
30 changes: 30 additions & 0 deletions
30
src/entities/ordensDeProducao/interfaces/update.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export interface IUpdateParams { | ||
/** | ||
* ID da ordem de produção | ||
*/ | ||
idOrdemProducao: number | ||
} | ||
|
||
export interface IUpdateBody { | ||
dataPrevisaoInicio?: string | ||
dataPrevisaoFinal?: string | ||
dataInicio?: string | ||
dataFim?: string | ||
numero: number | ||
responsavel?: string | ||
deposito: { | ||
idDestino?: number | ||
idOrigem?: number | ||
} | ||
situacao: { | ||
id: number | ||
} | ||
itens?: { | ||
produto?: { | ||
id: number | ||
} | ||
quantidade?: number | ||
}[] | ||
|
||
observacoes?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/entities/propostasComerciais/__tests__/change-situation-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default null | ||
|
||
export const changeSituationRequest = { | ||
situacao: 'A' as const | ||
} |
69 changes: 69 additions & 0 deletions
69
src/entities/propostasComerciais/__tests__/create-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
export default { | ||
data: { | ||
id: 12345678 | ||
} | ||
} | ||
|
||
export const createRequestBody = { | ||
data: "2024-04-29", | ||
situacao: "Concluído", | ||
numero: 13, | ||
contato: { | ||
id: 12345678 | ||
}, | ||
loja: { | ||
id: 12345678 | ||
}, | ||
desconto: 10, | ||
outrasDespesas: 11, | ||
garantia: 3, | ||
dataProximoContato: "2024-05-01", | ||
observacoes: "Observações da proposta comercial", | ||
observacaoInterna: "Observações internas da proposta comercial", | ||
totalOutrosItens: 1, | ||
aosCuidadosDe: "Nome do Contato", | ||
introducao: "Introdução da proposta comercial", | ||
prazoEntrega: "Prazo de entrega proposta comercial", | ||
itens: [ | ||
{ | ||
produto: { | ||
id: 12345678, | ||
descricao: "Bolo" | ||
}, | ||
codigo: "BLG-5", | ||
unidade: "UN", | ||
quantidade: 1.1, | ||
desconto: 1.2, | ||
valor: 3.1, | ||
descricaoDetalhada: "Descrição detalhada do produto" | ||
} | ||
], | ||
parcelas: [ | ||
{ | ||
numeroDias: 10, | ||
dataVencimento: "2024-04-29", | ||
valor: 10.55, | ||
observacoes: "Observacao da forma de pagamento", | ||
formaPagamento: [ | ||
{ | ||
id: 12345678 | ||
} | ||
] | ||
} | ||
], | ||
vendedor: { | ||
id: 12345678 | ||
}, | ||
transporte: { | ||
freteModalidade: 0 as const, | ||
frete: 2.34, | ||
quantidadeVolumes: 2.33, | ||
prazoEntrega: 2, | ||
pesoBruto: 2.4, | ||
contato: { | ||
id: 12345678, | ||
nome: "Nome do transportador" | ||
}, | ||
volumes: {} | ||
} | ||
} |
Oops, something went wrong.