Skip to content

Commit

Permalink
feat: adicionar vendedores
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Dec 9, 2023
1 parent ad0a324 commit ee1bfc4
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ As entidades atualmente permitidas para interação são:
- [x] Situações - Módulos (`.situacoesModulos`)
- [x] Situações - Transições (`.situacoesTransicoes`)
- [x] Usuários (`.usuarios`)
- [ ] Vendedores (`.vendedores`)
- [x] Vendedores (`.vendedores`)

Adicionaremos as restantes de acordo com as _releases_.

Expand Down
5 changes: 5 additions & 0 deletions src/bling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { Situacoes } from './entities/situacoes'
import { SituacoesModulos } from './entities/situacoesModulos'
import { SituacoesTransicoes } from './entities/situacoesTransicoes'
import { Usuarios } from './entities/usuarios'
import { Vendedores } from './entities/vendedores'

const chance = Chance()

Expand Down Expand Up @@ -228,4 +229,8 @@ describe('Bling main module', () => {
it('should retrieve usuários entity', () => {
expect(createBling(chance.word()).usuarios).toBeInstanceOf(Usuarios)
})

it('should retrieve vendedores entity', () => {
expect(createBling(chance.word()).vendedores).toBeInstanceOf(Vendedores)
})
})
11 changes: 11 additions & 0 deletions src/bling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { Situacoes } from './entities/situacoes'
import { SituacoesModulos } from './entities/situacoesModulos'
import { SituacoesTransicoes } from './entities/situacoesTransicoes'
import { Usuarios } from './entities/usuarios'
import { Vendedores } from './entities/vendedores'
import { Newable } from './helpers/types/newable.type'
import { getRepository } from './providers/ioc'
import { IBlingRepository } from './repositories/bling.repository.interface'
Expand Down Expand Up @@ -399,4 +400,14 @@ export default class Bling {
public get usuarios(): Usuarios {
return this.getModule(Usuarios)
}

/**
*
* Obtém a instância de interação com vendedores.
*
* @return {Vendedores}
*/
public get vendedores(): Vendedores {
return this.getModule(Vendedores)
}
}
20 changes: 20 additions & 0 deletions src/entities/vendedores/__tests__/find-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
data: {
id: 12345678,
descontoLimite: 10.12,
loja: {
id: 12345678
},
contato: {
id: 12345678,
nome: 'Vendedor',
situacao: 'A'
},
comissoes: [
{
descontoMaximo: 10,
aliquota: 2
}
]
}
}
14 changes: 14 additions & 0 deletions src/entities/vendedores/__tests__/get-response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {
data: {
id: 12345678,
descontoLimite: 10.12,
loja: {
id: 12345678
},
contato: {
id: 12345678,
nome: 'Vendedor',
situacao: 'A'
}
}
}
57 changes: 57 additions & 0 deletions src/entities/vendedores/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Chance } from 'chance'
import { Vendedores } from '..'
import { InMemoryBlingRepository } from '../../../repositories/bling-in-memory.repository'
import findResponse from './find-response'
import getResponse from './get-response'

const chance = Chance()

describe('Vendedores entity', () => {
let repository: InMemoryBlingRepository
let entity: Vendedores

beforeEach(() => {
repository = new InMemoryBlingRepository()
entity = new Vendedores(repository)
})

afterEach(() => {
jest.restoreAllMocks()
})

it('should get successfully', async () => {
const spy = jest.spyOn(repository, 'index')
repository.setResponse(getResponse)

const response = await entity.get()

expect(spy).toHaveBeenCalledWith({
endpoint: 'vendedores',
params: {
limite: undefined,
pagina: undefined,
nomeContato: undefined,
situacaoContato: undefined,
idContato: undefined,
idLoja: undefined,
dataAlteracaoInicial: undefined,
dataAlteracaoFinal: undefined
}
})
expect(response).toBe(getResponse)
})

it('should find successfully', async () => {
const spy = jest.spyOn(repository, 'show')
const idVendedor = chance.natural()
repository.setResponse(findResponse)

const response = await entity.find({ idVendedor })

expect(spy).toHaveBeenCalledWith({
endpoint: 'vendedores',
id: String(idVendedor)
})
expect(response).toBe(findResponse)
})
})
57 changes: 57 additions & 0 deletions src/entities/vendedores/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Entity } from '../@shared/entity'
import { IFindParams, IFindResponse } from './interfaces/find.interface'
import { IGetParams, IGetResponse } from './interfaces/get.interface'

/**
* Entidade para interação com vendedores.
*
* @see https://developer.bling.com.br/referencia#/Vendedores
*/
export class Vendedores extends Entity {
/**
* Obtém vendedores.
*
* @param {IGetParams} params Parâmetros da busca.
*
* @returns {Promise<IGetResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Vendedores/get_vendedores
*/
public async get(params?: IGetParams): Promise<IGetResponse> {
return await this.repository.index({
endpoint: 'vendedores',
params: {
pagina: params?.pagina,
limite: params?.limite,
nomeContato: params?.nomeContato,
situacaoContato: params?.situacaoContato,
idContato: params?.idContato,
idLoja: params?.idLoja,
dataAlteracaoInicial: this.prepareStringOrDateParam(
params?.dataAlteracaoInicial
),
dataAlteracaoFinal: this.prepareStringOrDateParam(
params?.dataAlteracaoFinal
)
}
})
}

/**
* Obtém um vendedor.
*
* @param {IFindParams} params Parâmetros da busca.
*
* @returns {Promise<IFindResponse>}
* @throws {BlingApiException|BlingInternalException}
*
* @see https://developer.bling.com.br/referencia#/Vendedores/get_vendedores__idVendedor_
*/
public async find(params: IFindParams): Promise<IFindResponse> {
return await this.repository.show({
endpoint: 'vendedores',
id: String(params.idVendedor)
})
}
}
25 changes: 25 additions & 0 deletions src/entities/vendedores/interfaces/find.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ISituacao } from '../types/situacao.type'

export interface IFindParams {
/**
* ID do vendedor
*/
idVendedor: number
}

export interface IFindResponse {
data: {
id?: number
descontoLimite?: number
loja?: { id: number }
contato: {
id: number
nome: string
situacao: ISituacao
}
comissoes: {
descontoMaximo: number
aliquota: number
}[]
}
}
49 changes: 49 additions & 0 deletions src/entities/vendedores/interfaces/get.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ISituacao } from '../types/situacao.type'

export interface IGetParams {
/**
* N° da página da listagem
*/
pagina?: number
/**
* Quantidade de registros que devem ser exibidos por página
*/
limite?: number
/**
* Nome do contato do vendedor
*/
nomeContato?: string
/**
* Situação do contato do vendedor
*/
situacaoContato?: ISituacao
/**
* ID do contato do vendedor
*/
idContato?: number
/**
* ID da loja vinculada ao vendedor
*/
idLoja?: number
/**
* Data de alteração inicial
*/
dataAlteracaoInicial?: Date | string
/**
* Data de alteração final
*/
dataAlteracaoFinal?: Date | string
}

export interface IGetResponse {
data: {
id?: number
descontoLimite?: number
loja?: { id: number }
contato: {
id: number
nome: string
situacao: ISituacao
}
}
}
9 changes: 9 additions & 0 deletions src/entities/vendedores/types/situacao.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Tipagem referente à situação do vendedor.
*
* - `A`: Ativo
* - `I`: Inativo
* - `S`: Sem movimento
* - `E`: Excluído
*/
export type ISituacao = 'A' | 'I' | 'S' | 'E'

0 comments on commit ee1bfc4

Please sign in to comment.