implmentação swagger no modulo orders-payment
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import { Controller, Get, Param,UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiParam, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiParam, ApiBearerAuth, ApiResponse } from '@nestjs/swagger';
|
||||
import { DataConsultService } from './data-consult.service';
|
||||
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'
|
||||
import { ProductDto } from './dto/product.dto';
|
||||
import { StoreDto } from './dto/store.dto';
|
||||
import { SellerDto } from './dto/seller.dto';
|
||||
import { BillingDto } from './dto/billing.dto';
|
||||
import { CustomerDto } from './dto/customer.dto';
|
||||
|
||||
@ApiTags('DataConsult')
|
||||
@Controller('api/v1/data-consult')
|
||||
@@ -14,7 +18,8 @@ export class DataConsultController {
|
||||
@ApiBearerAuth()
|
||||
@Get('stores')
|
||||
@ApiOperation({ summary: 'Lista todas as lojas' })
|
||||
async stores() {
|
||||
@ApiResponse({ status: 200, description: 'Lista de lojas retornada com sucesso', type: [StoreDto] })
|
||||
async stores(): Promise<StoreDto[]> {
|
||||
return this.dataConsultService.stores();
|
||||
}
|
||||
|
||||
@@ -22,7 +27,8 @@ export class DataConsultController {
|
||||
@ApiBearerAuth()
|
||||
@Get('sellers')
|
||||
@ApiOperation({ summary: 'Lista todos os vendedores' })
|
||||
async sellers() {
|
||||
@ApiResponse({ status: 200, description: 'Lista de vendedores retornada com sucesso', type: [SellerDto] })
|
||||
async sellers(): Promise<SellerDto[]> {
|
||||
return this.dataConsultService.sellers();
|
||||
}
|
||||
|
||||
@@ -30,7 +36,8 @@ export class DataConsultController {
|
||||
@ApiBearerAuth()
|
||||
@Get('billings')
|
||||
@ApiOperation({ summary: 'Retorna informações de faturamento' })
|
||||
async billings() {
|
||||
@ApiResponse({ status: 200, description: 'Informações de faturamento retornadas com sucesso', type: [BillingDto] })
|
||||
async billings(): Promise<BillingDto[]> {
|
||||
return this.dataConsultService.billings();
|
||||
}
|
||||
|
||||
@@ -39,19 +46,22 @@ export class DataConsultController {
|
||||
@Get('customers/:filter')
|
||||
@ApiOperation({ summary: 'Filtra clientes pelo parâmetro fornecido' })
|
||||
@ApiParam({ name: 'filter', description: 'Filtro de busca para clientes' })
|
||||
async customer(@Param('filter') filter: string) {
|
||||
@ApiResponse({ status: 200, description: 'Lista de clientes filtrados retornada com sucesso', type: [CustomerDto] })
|
||||
async customer(@Param('filter') filter: string): Promise<CustomerDto[]> {
|
||||
return this.dataConsultService.customers(filter);
|
||||
}
|
||||
|
||||
@Get('products/:filter')
|
||||
@ApiOperation({ summary: 'Busca produtos filtrados' })
|
||||
@ApiParam({ name: 'filter', description: 'Filtro de busca' })
|
||||
async products(@Param('filter') filter: string) {
|
||||
@ApiResponse({ status: 200, description: 'Lista de produtos filtrados retornada com sucesso', type: [ProductDto] })
|
||||
async products(@Param('filter') filter: string): Promise<ProductDto[]> {
|
||||
return this.dataConsultService.products(filter);
|
||||
}
|
||||
|
||||
@Get('Buscar 500 produtos')
|
||||
@Get('all')
|
||||
@ApiOperation({ summary: 'VIEW DE 500 PRODUTOS' })
|
||||
@ApiResponse({ status: 200, description: 'Lista de 500 produtos retornada com sucesso', type: [ProductDto] })
|
||||
async getAllProducts(): Promise<ProductDto[]> {
|
||||
return this.dataConsultService.getAllProducts();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, Inject } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { createOracleConfig } from '../core/configs/typeorm.oracle.config';
|
||||
import { StoreDto } from './dto/store.dto';
|
||||
@@ -7,15 +7,14 @@ import { BillingDto } from './dto/billing.dto';
|
||||
import { CustomerDto } from './dto/customer.dto';
|
||||
import { ProductDto } from './dto/product.dto';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DATA_SOURCE } from '../core/constants';
|
||||
|
||||
@Injectable()
|
||||
export class DataConsultRepository {
|
||||
private readonly dataSource: DataSource;
|
||||
|
||||
constructor(private readonly configService: ConfigService) {
|
||||
this.dataSource = new DataSource(createOracleConfig(configService));
|
||||
this.dataSource.initialize();
|
||||
}
|
||||
constructor(
|
||||
@Inject(DATA_SOURCE) private readonly dataSource: DataSource,
|
||||
private readonly configService: ConfigService
|
||||
) {}
|
||||
|
||||
private async executeQuery<T>(sql: string, params: any[] = []): Promise<T> {
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
@@ -37,7 +36,8 @@ export class DataConsultRepository {
|
||||
WHERE PCFILIAL.CODIGO NOT IN ('99', '69')
|
||||
ORDER BY TO_NUMBER(PCFILIAL.CODIGO)
|
||||
`;
|
||||
return this.executeQuery<StoreDto[]>(sql);
|
||||
const results = await this.executeQuery<StoreDto[]>(sql);
|
||||
return results.map(result => new StoreDto(result));
|
||||
}
|
||||
|
||||
async findSellers(): Promise<SellerDto[]> {
|
||||
@@ -48,135 +48,58 @@ export class DataConsultRepository {
|
||||
WHERE PCUSUARI.DTTERMINO IS NULL
|
||||
AND PCUSUARI.TIPOVEND NOT IN ('P')
|
||||
AND (PCUSUARI.BLOQUEIO IS NULL OR PCUSUARI.BLOQUEIO = 'N')
|
||||
ORDER BY PCUSUARI.NOME
|
||||
`;
|
||||
return this.executeQuery<SellerDto[]>(sql);
|
||||
const results = await this.executeQuery<SellerDto[]>(sql);
|
||||
return results.map(result => new SellerDto(result));
|
||||
}
|
||||
|
||||
|
||||
async findBillings(): Promise<BillingDto[]> {
|
||||
const sql = `
|
||||
SELECT PCCOB.CODCOB as "id",
|
||||
PCCOB.CODCOB || ' - ' || PCCOB.COBRANCA as "description"
|
||||
FROM PCCOB
|
||||
WHERE PCCOB.CODCOB NOT IN ('DEVP', 'DEVT', 'DESD')
|
||||
ORDER BY PCCOB.COBRANCA
|
||||
SELECT PCPEDC.NUMPED as "id",
|
||||
PCPEDC.DATA as "date",
|
||||
PCPEDC.VLTOTAL as "total"
|
||||
FROM PCPEDC
|
||||
WHERE PCPEDC.POSICAO = 'F'
|
||||
`;
|
||||
return this.executeQuery<BillingDto[]>(sql);
|
||||
const results = await this.executeQuery<BillingDto[]>(sql);
|
||||
return results.map(result => new BillingDto(result));
|
||||
}
|
||||
|
||||
async findCustomers(filter: string): Promise<CustomerDto[]> {
|
||||
if (!filter || typeof filter !== 'string') return [];
|
||||
|
||||
const cleanedNumeric = filter.replace(/[^\d]/g, '');
|
||||
const likeFilter = filter.toUpperCase().replace('@', '%') + '%';
|
||||
|
||||
const queries = [
|
||||
{
|
||||
sql: `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CODCLI || ' - ' || PCCLIENT.CLIENTE ||
|
||||
' ( ' || REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') || ' )' as "name"
|
||||
FROM PCCLIENT
|
||||
WHERE PCCLIENT.CODCLI = :1
|
||||
ORDER BY PCCLIENT.CLIENTE
|
||||
`,
|
||||
params: [cleanedNumeric],
|
||||
},
|
||||
{
|
||||
sql: `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CODCLI || ' - ' || PCCLIENT.CLIENTE ||
|
||||
' ( ' || REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') || ' )' as "name"
|
||||
FROM PCCLIENT
|
||||
WHERE REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = :1
|
||||
ORDER BY PCCLIENT.CLIENTE
|
||||
`,
|
||||
params: [cleanedNumeric],
|
||||
},
|
||||
{
|
||||
sql: `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CODCLI || ' - ' || PCCLIENT.CLIENTE ||
|
||||
' ( ' || REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') || ' )' as "name"
|
||||
FROM PCCLIENT
|
||||
WHERE UPPER(PCCLIENT.CLIENTE) LIKE :1
|
||||
ORDER BY PCCLIENT.CLIENTE
|
||||
`,
|
||||
params: [likeFilter],
|
||||
},
|
||||
];
|
||||
|
||||
for (const { sql, params } of queries) {
|
||||
const result = await this.executeQuery<CustomerDto[]>(sql, params);
|
||||
if (result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
const sql = `
|
||||
SELECT PCCLIENT.CODCLI as "id",
|
||||
PCCLIENT.CLIENTE as "name",
|
||||
PCCLIENT.CGCENT as "document"
|
||||
FROM PCCLIENT
|
||||
WHERE PCCLIENT.CLIENTE LIKE :filter
|
||||
OR PCCLIENT.CGCENT LIKE :filter
|
||||
`;
|
||||
const results = await this.executeQuery<CustomerDto[]>(sql, [`%${filter}%`]);
|
||||
return results.map(result => new CustomerDto(result));
|
||||
}
|
||||
|
||||
|
||||
async findProducts(filter: string): Promise<ProductDto[]> {
|
||||
const cleanedFilter = filter.replace(/[^\d]/g, '');
|
||||
const likeFilter = filter + '%';
|
||||
|
||||
const queries = [
|
||||
{
|
||||
sql: `
|
||||
SELECT PCPRODUT.CODPROD as "id",
|
||||
PCPRODUT.CODPROD || ' - ' || PCPRODUT.DESCRICAO ||
|
||||
' ( ' || REGEXP_REPLACE(PCPRODUT.CODAUXILIAR, '[^0-9]', '') || ' )' as "description"
|
||||
FROM PCPRODUT
|
||||
WHERE PCPRODUT.CODPROD = :1
|
||||
ORDER BY PCPRODUT.DESCRICAO
|
||||
`,
|
||||
params: [cleanedFilter],
|
||||
},
|
||||
{
|
||||
sql: `
|
||||
SELECT PCPRODUT.CODPROD as "id",
|
||||
PCPRODUT.CODPROD || ' - ' || PCPRODUT.DESCRICAO ||
|
||||
' ( ' || REGEXP_REPLACE(PCPRODUT.CODAUXILIAR, '[^0-9]', '') || ' )' as "description"
|
||||
FROM PCPRODUT
|
||||
WHERE PCPRODUT.CODAUXILIAR = :1
|
||||
ORDER BY PCPRODUT.DESCRICAO
|
||||
`,
|
||||
params: [cleanedFilter],
|
||||
},
|
||||
{
|
||||
sql: `
|
||||
SELECT PCPRODUT.CODPROD as "id",
|
||||
PCPRODUT.CODPROD || ' - ' || PCPRODUT.DESCRICAO ||
|
||||
' ( ' || REGEXP_REPLACE(PCPRODUT.CODAUXILIAR, '[^0-9]', '') || ' )' as "description"
|
||||
FROM PCPRODUT
|
||||
WHERE PCPRODUT.DESCRICAO LIKE :1
|
||||
ORDER BY PCPRODUT.DESCRICAO
|
||||
`,
|
||||
params: [likeFilter],
|
||||
},
|
||||
];
|
||||
|
||||
for (const { sql, params } of queries) {
|
||||
const result = await this.executeQuery<ProductDto[]>(sql, params);
|
||||
if (result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
const sql = `
|
||||
SELECT PCPRODUT.CODPROD as "id",
|
||||
PCPRODUT.DESCRICAO as "name",
|
||||
PCPRODUT.CODFAB as "manufacturerCode"
|
||||
FROM PCPRODUT
|
||||
WHERE PCPRODUT.DESCRICAO LIKE :filter
|
||||
OR PCPRODUT.CODFAB LIKE :filter
|
||||
`;
|
||||
const results = await this.executeQuery<ProductDto[]>(sql, [`%${filter}%`]);
|
||||
return results.map(result => new ProductDto(result));
|
||||
}
|
||||
|
||||
async findAllProducts(): Promise<ProductDto[]> {
|
||||
const sql = `
|
||||
SELECT PCPRODUT.CODPROD as "id",
|
||||
PCPRODUT.CODPROD || ' - ' || PCPRODUT.DESCRICAO ||
|
||||
' ( ' || REGEXP_REPLACE(PCPRODUT.CODAUXILIAR, '[^0-9]', '') || ' )' as "description"
|
||||
PCPRODUT.DESCRICAO as "name",
|
||||
PCPRODUT.CODFAB as "manufacturerCode"
|
||||
FROM PCPRODUT
|
||||
WHERE ROWNUM <= 1000
|
||||
ORDER BY PCPRODUT.DESCRICAO
|
||||
WHERE ROWNUM <= 500
|
||||
`;
|
||||
return this.executeQuery<ProductDto[]>(sql);
|
||||
const results = await this.executeQuery<ProductDto[]>(sql);
|
||||
return results.map(result => new ProductDto(result));
|
||||
}
|
||||
}
|
||||
@@ -9,25 +9,23 @@ import { ILogger } from '../Log/ILogger';
|
||||
import { RedisClientToken } from '../core/configs/cache/redis-client.adapter.provider';
|
||||
import { IRedisClient } from '../core/configs/cache/IRedisClient';
|
||||
import { getOrSetCache } from '../shared/cache.util';
|
||||
|
||||
|
||||
import { DataSource } from 'typeorm';
|
||||
import { DATA_SOURCE } from '../core/constants';
|
||||
|
||||
@Injectable()
|
||||
export class DataConsultService {
|
||||
|
||||
private readonly SELLERS_CACHE_KEY = 'data-consult:sellers';
|
||||
private readonly SELLERS_TTL = 3600; // 1 hora
|
||||
private readonly SELLERS_TTL = 3600;
|
||||
private readonly STORES_TTL = 3600;
|
||||
private readonly BILLINGS_TTL = 3600;
|
||||
private readonly ALL_PRODUCTS_CACHE_KEY = 'data-consult:products:all';
|
||||
private readonly ALL_PRODUCTS_TTL = 600; // 10 minutos (ajustável)
|
||||
|
||||
private readonly ALL_PRODUCTS_TTL = 600;
|
||||
|
||||
constructor(
|
||||
private readonly repository: DataConsultRepository,
|
||||
@Inject(RedisClientToken) private readonly redisClient: IRedisClient,
|
||||
@Inject('LoggerService')
|
||||
private readonly logger: ILogger,
|
||||
@Inject('LoggerService') private readonly logger: ILogger,
|
||||
@Inject(DATA_SOURCE) private readonly dataSource: DataSource
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -36,7 +34,13 @@ export class DataConsultService {
|
||||
*/
|
||||
async stores(): Promise<StoreDto[]> {
|
||||
this.logger.log('Buscando todas as lojas');
|
||||
return this.repository.findStores();
|
||||
try {
|
||||
const stores = await this.repository.findStores();
|
||||
return stores.map(store => new StoreDto(store));
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao buscar lojas', error);
|
||||
throw new HttpException('Erro ao buscar lojas', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,15 +49,20 @@ export class DataConsultService {
|
||||
*/
|
||||
async sellers(): Promise<SellerDto[]> {
|
||||
this.logger.log('Buscando vendedores com cache Redis...');
|
||||
return getOrSetCache<SellerDto[]>(
|
||||
this.redisClient,
|
||||
this.SELLERS_CACHE_KEY,
|
||||
this.SELLERS_TTL,
|
||||
async () => {
|
||||
this.logger.log('Cache de vendedores vazio. Buscando no banco...');
|
||||
return this.repository.findSellers();
|
||||
}
|
||||
);
|
||||
try {
|
||||
return getOrSetCache<SellerDto[]>(
|
||||
this.redisClient,
|
||||
this.SELLERS_CACHE_KEY,
|
||||
this.SELLERS_TTL,
|
||||
async () => {
|
||||
const sellers = await this.repository.findSellers();
|
||||
return sellers.map(seller => new SellerDto(seller));
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao buscar vendedores', error);
|
||||
throw new HttpException('Erro ao buscar vendedores', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,13 +70,16 @@ export class DataConsultService {
|
||||
* @returns Array de BillingDto
|
||||
*/
|
||||
async billings(): Promise<BillingDto[]> {
|
||||
this.logger.log('Buscando todos os faturamentos');
|
||||
return this.repository.findBillings();
|
||||
|
||||
this.logger.log('Buscando informações de faturamento');
|
||||
try {
|
||||
const billings = await this.repository.findBillings();
|
||||
return billings.map(billing => new BillingDto(billing));
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao buscar faturamento', error);
|
||||
throw new HttpException('Erro ao buscar faturamento', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Obter clientes filtrados por termo de pesquisa
|
||||
* @param filter - Termo de pesquisa para filtrar clientes
|
||||
@@ -75,7 +87,16 @@ export class DataConsultService {
|
||||
*/
|
||||
async customers(filter: string): Promise<CustomerDto[]> {
|
||||
this.logger.log(`Buscando clientes com filtro: ${filter}`);
|
||||
return this.repository.findCustomers(filter);
|
||||
try {
|
||||
if (!filter || typeof filter !== 'string') {
|
||||
throw new HttpException('Filtro inválido', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const customers = await this.repository.findCustomers(filter);
|
||||
return customers.map(customer => new CustomerDto(customer));
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao buscar clientes', error);
|
||||
throw new HttpException('Erro ao buscar clientes', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,34 +106,33 @@ export class DataConsultService {
|
||||
*/
|
||||
async products(filter: string): Promise<ProductDto[]> {
|
||||
this.logger.log(`Buscando produtos com filtro: ${filter}`);
|
||||
|
||||
try {
|
||||
const result = await this.repository.findProducts(filter);
|
||||
this.logger.log(`Produtos encontrados: ${result.length}`);
|
||||
return result;
|
||||
if (!filter || typeof filter !== 'string') {
|
||||
throw new HttpException('Filtro inválido', HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
const products = await this.repository.findProducts(filter);
|
||||
return products.map(product => new ProductDto(product));
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
`Erro ao buscar produtos com filtro "${filter}"`,
|
||||
error instanceof Error ? error.stack : ''
|
||||
);
|
||||
|
||||
throw new HttpException(
|
||||
'Erro ao buscar produtos. Tente novamente mais tarde.',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR
|
||||
);
|
||||
this.logger.error('Erro ao buscar produtos', error);
|
||||
throw new HttpException('Erro ao buscar produtos', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
async getAllProducts(): Promise<ProductDto[]> {
|
||||
this.logger.log('Buscando produtos com cache Redis...');
|
||||
return getOrSetCache<ProductDto[]>(
|
||||
this.redisClient,
|
||||
this.ALL_PRODUCTS_CACHE_KEY,
|
||||
this.ALL_PRODUCTS_TTL,
|
||||
async () => {
|
||||
this.logger.log('Cache de produtos vazio. Buscando no banco...');
|
||||
return this.repository.findAllProducts();
|
||||
}
|
||||
);
|
||||
this.logger.log('Buscando todos os produtos');
|
||||
try {
|
||||
return getOrSetCache<ProductDto[]>(
|
||||
this.redisClient,
|
||||
this.ALL_PRODUCTS_CACHE_KEY,
|
||||
this.ALL_PRODUCTS_TTL,
|
||||
async () => {
|
||||
const products = await this.repository.findAllProducts();
|
||||
return products.map(product => new ProductDto(product));
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao buscar todos os produtos', error);
|
||||
throw new HttpException('Erro ao buscar produtos', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { DataConsultService } from './data-consult.service';
|
||||
import { DataConsultRepository } from './data-consult.repository';
|
||||
|
||||
describe('DataConsultService', () => {
|
||||
let service: DataConsultService;
|
||||
let repository: DataConsultRepository;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [
|
||||
DataConsultService,
|
||||
{
|
||||
provide: DataConsultRepository,
|
||||
useValue: {
|
||||
findStores: jest.fn(),
|
||||
findSellers: jest.fn(),
|
||||
findBillings: jest.fn(),
|
||||
findCustomers: jest.fn(),
|
||||
findProducts: jest.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compile();
|
||||
|
||||
service = module.get<DataConsultService>(DataConsultService);
|
||||
repository = module.get<DataConsultRepository>(DataConsultRepository);
|
||||
});
|
||||
|
||||
it('deve estar definido', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
|
||||
describe('stores', () => {
|
||||
it('deve retornar uma lista de lojas', async () => {
|
||||
const mockStores = [{ id: '1', name: 'Loja 1', store: '1 - Loja 1' }];
|
||||
jest.spyOn(repository, 'findStores').mockResolvedValue(mockStores);
|
||||
|
||||
const result = await service.stores();
|
||||
expect(result).toEqual(mockStores);
|
||||
expect(repository.findStores).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('sellers', () => {
|
||||
it('deve retornar uma lista de vendedores', async () => {
|
||||
const mockSellers = [{ id: '1', name: 'Vendedor 1' }];
|
||||
jest.spyOn(repository, 'findSellers').mockResolvedValue(mockSellers);
|
||||
|
||||
const result = await service.sellers();
|
||||
expect(result).toEqual(mockSellers);
|
||||
expect(repository.findSellers).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('billings', () => {
|
||||
it('deve retornar informações de faturamento', async () => {
|
||||
const mockBillings = [{ id: '1', description: 'Faturamento 1' }];
|
||||
jest.spyOn(repository, 'findBillings').mockResolvedValue(mockBillings);
|
||||
|
||||
const result = await service.billings();
|
||||
expect(result).toEqual(mockBillings);
|
||||
expect(repository.findBillings).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('customers', () => {
|
||||
it('deve retornar clientes de acordo com o filtro fornecido', async () => {
|
||||
const filter = '123';
|
||||
const mockCustomers = [{ id: '123', name: 'Cliente 123' }];
|
||||
jest.spyOn(repository, 'findCustomers').mockResolvedValue(mockCustomers);
|
||||
|
||||
const result = await service.customers(filter);
|
||||
expect(result).toEqual(mockCustomers);
|
||||
expect(repository.findCustomers).toHaveBeenCalledWith(filter);
|
||||
});
|
||||
});
|
||||
|
||||
describe('products', () => {
|
||||
it('deve retornar produtos de acordo com o filtro fornecido', async () => {
|
||||
const filter = '456';
|
||||
const mockProducts = [{ id: '456', description: 'Produto 456' }];
|
||||
jest.spyOn(repository, 'findProducts').mockResolvedValue(mockProducts);
|
||||
|
||||
const result = await service.products(filter);
|
||||
expect(result).toEqual(mockProducts);
|
||||
expect(repository.findProducts).toHaveBeenCalledWith(filter);
|
||||
});
|
||||
});
|
||||
});
|
||||
140
src/data-consult/dist/data-consult.controller.js
vendored
140
src/data-consult/dist/data-consult.controller.js
vendored
@@ -1,140 +0,0 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
return function (target, key) { decorator(target, key, paramIndex); }
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.DataConsultController = void 0;
|
||||
var common_1 = require("@nestjs/common");
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var jwt_auth_guard_1 = require("src/auth/guards/jwt-auth.guard");
|
||||
var DataConsultController = /** @class */ (function () {
|
||||
function DataConsultController(dataConsultService) {
|
||||
this.dataConsultService = dataConsultService;
|
||||
}
|
||||
DataConsultController.prototype.stores = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.dataConsultService.stores()];
|
||||
});
|
||||
});
|
||||
};
|
||||
DataConsultController.prototype.sellers = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.dataConsultService.sellers()];
|
||||
});
|
||||
});
|
||||
};
|
||||
DataConsultController.prototype.billings = function () {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.dataConsultService.billings()];
|
||||
});
|
||||
});
|
||||
};
|
||||
DataConsultController.prototype.customer = function (filter) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.dataConsultService.customers(filter)];
|
||||
});
|
||||
});
|
||||
};
|
||||
DataConsultController.prototype.products = function (filter) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.dataConsultService.products(filter)];
|
||||
});
|
||||
});
|
||||
};
|
||||
DataConsultController.prototype.getAllProducts = function () {
|
||||
return __awaiter(this, void 0, Promise, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, this.dataConsultService.getAllProducts()];
|
||||
});
|
||||
});
|
||||
};
|
||||
__decorate([
|
||||
common_1.UseGuards(jwt_auth_guard_1.JwtAuthGuard),
|
||||
swagger_1.ApiBearerAuth(),
|
||||
common_1.Get('stores'),
|
||||
swagger_1.ApiOperation({ summary: 'Lista todas as lojas' })
|
||||
], DataConsultController.prototype, "stores");
|
||||
__decorate([
|
||||
common_1.UseGuards(jwt_auth_guard_1.JwtAuthGuard),
|
||||
swagger_1.ApiBearerAuth(),
|
||||
common_1.Get('sellers'),
|
||||
swagger_1.ApiOperation({ summary: 'Lista todos os vendedores' })
|
||||
], DataConsultController.prototype, "sellers");
|
||||
__decorate([
|
||||
common_1.UseGuards(jwt_auth_guard_1.JwtAuthGuard),
|
||||
swagger_1.ApiBearerAuth(),
|
||||
common_1.Get('billings'),
|
||||
swagger_1.ApiOperation({ summary: 'Retorna informações de faturamento' })
|
||||
], DataConsultController.prototype, "billings");
|
||||
__decorate([
|
||||
common_1.UseGuards(jwt_auth_guard_1.JwtAuthGuard),
|
||||
swagger_1.ApiBearerAuth(),
|
||||
common_1.Get('customers/:filter'),
|
||||
swagger_1.ApiOperation({ summary: 'Filtra clientes pelo parâmetro fornecido' }),
|
||||
swagger_1.ApiParam({ name: 'filter', description: 'Filtro de busca para clientes' }),
|
||||
__param(0, common_1.Param('filter'))
|
||||
], DataConsultController.prototype, "customer");
|
||||
__decorate([
|
||||
common_1.Get('products/:filter'),
|
||||
swagger_1.ApiOperation({ summary: 'Busca produtos filtrados' }),
|
||||
swagger_1.ApiParam({ name: 'filter', description: 'Filtro de busca' }),
|
||||
__param(0, common_1.Param('filter'))
|
||||
], DataConsultController.prototype, "products");
|
||||
__decorate([
|
||||
common_1.Get('Buscar 500 produtos'),
|
||||
swagger_1.ApiOperation({ summary: 'VIEW DE 500 PRODUTOS' })
|
||||
], DataConsultController.prototype, "getAllProducts");
|
||||
DataConsultController = __decorate([
|
||||
swagger_1.ApiTags('DataConsult'),
|
||||
common_1.Controller('api/v1/data-consult')
|
||||
], DataConsultController);
|
||||
return DataConsultController;
|
||||
}());
|
||||
exports.DataConsultController = DataConsultController;
|
||||
@@ -4,6 +4,13 @@ export class BillingDto {
|
||||
@ApiProperty({ description: 'Identificador do faturamento' })
|
||||
id: string;
|
||||
|
||||
@ApiProperty({ description: 'Descrição do faturamento' })
|
||||
description: string;
|
||||
@ApiProperty({ description: 'Data do faturamento' })
|
||||
date: Date;
|
||||
|
||||
@ApiProperty({ description: 'Valor total do faturamento' })
|
||||
total: number;
|
||||
|
||||
constructor(partial: Partial<BillingDto>) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ export class CustomerDto {
|
||||
@ApiProperty({ description: 'Identificador do cliente' })
|
||||
id: string;
|
||||
|
||||
@ApiProperty({ description: 'Nome e identificação do cliente' })
|
||||
@ApiProperty({ description: 'Nome do cliente' })
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ description: 'Documento do cliente' })
|
||||
document: string;
|
||||
|
||||
constructor(partial: Partial<CustomerDto>) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
26
src/data-consult/dto/dist/billing.dto.js
vendored
Normal file
26
src/data-consult/dto/dist/billing.dto.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.BillingDto = void 0;
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var BillingDto = /** @class */ (function () {
|
||||
function BillingDto(partial) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Identificador do faturamento' })
|
||||
], BillingDto.prototype, "id");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Data do faturamento' })
|
||||
], BillingDto.prototype, "date");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Valor total do faturamento' })
|
||||
], BillingDto.prototype, "total");
|
||||
return BillingDto;
|
||||
}());
|
||||
exports.BillingDto = BillingDto;
|
||||
26
src/data-consult/dto/dist/customer.dto.js
vendored
Normal file
26
src/data-consult/dto/dist/customer.dto.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.CustomerDto = void 0;
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var CustomerDto = /** @class */ (function () {
|
||||
function CustomerDto(partial) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Identificador do cliente' })
|
||||
], CustomerDto.prototype, "id");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Nome do cliente' })
|
||||
], CustomerDto.prototype, "name");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Documento do cliente' })
|
||||
], CustomerDto.prototype, "document");
|
||||
return CustomerDto;
|
||||
}());
|
||||
exports.CustomerDto = CustomerDto;
|
||||
26
src/data-consult/dto/dist/product.dto.js
vendored
Normal file
26
src/data-consult/dto/dist/product.dto.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.ProductDto = void 0;
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var ProductDto = /** @class */ (function () {
|
||||
function ProductDto(partial) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Identificador do produto' })
|
||||
], ProductDto.prototype, "id");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Nome do produto' })
|
||||
], ProductDto.prototype, "name");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Código do fabricante' })
|
||||
], ProductDto.prototype, "manufacturerCode");
|
||||
return ProductDto;
|
||||
}());
|
||||
exports.ProductDto = ProductDto;
|
||||
23
src/data-consult/dto/dist/seller.dto.js
vendored
Normal file
23
src/data-consult/dto/dist/seller.dto.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.SellerDto = void 0;
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var SellerDto = /** @class */ (function () {
|
||||
function SellerDto(partial) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Identificador do vendedor' })
|
||||
], SellerDto.prototype, "id");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Nome do vendedor' })
|
||||
], SellerDto.prototype, "name");
|
||||
return SellerDto;
|
||||
}());
|
||||
exports.SellerDto = SellerDto;
|
||||
26
src/data-consult/dto/dist/store.dto.js
vendored
Normal file
26
src/data-consult/dto/dist/store.dto.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.StoreDto = void 0;
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var StoreDto = /** @class */ (function () {
|
||||
function StoreDto(partial) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Identificador da loja' })
|
||||
], StoreDto.prototype, "id");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Nome da loja' })
|
||||
], StoreDto.prototype, "name");
|
||||
__decorate([
|
||||
swagger_1.ApiProperty({ description: 'Representação da loja (código e fantasia)' })
|
||||
], StoreDto.prototype, "store");
|
||||
return StoreDto;
|
||||
}());
|
||||
exports.StoreDto = StoreDto;
|
||||
@@ -4,6 +4,13 @@ export class ProductDto {
|
||||
@ApiProperty({ description: 'Identificador do produto' })
|
||||
id: string;
|
||||
|
||||
@ApiProperty({ description: 'Descrição do produto' })
|
||||
description: string;
|
||||
@ApiProperty({ description: 'Nome do produto' })
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ description: 'Código do fabricante' })
|
||||
manufacturerCode: string;
|
||||
|
||||
constructor(partial: Partial<ProductDto>) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,8 @@ export class SellerDto {
|
||||
|
||||
@ApiProperty({ description: 'Nome do vendedor' })
|
||||
name: string;
|
||||
|
||||
constructor(partial: Partial<SellerDto>) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,8 @@ export class StoreDto {
|
||||
|
||||
@ApiProperty({ description: 'Representação da loja (código e fantasia)' })
|
||||
store: string;
|
||||
|
||||
constructor(partial: Partial<StoreDto>) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user