fix: ajuste no endpoint de impressão de pedidos.
This commit is contained in:
@@ -7,6 +7,7 @@ import { StoreDto } from './dto/store.dto';
|
||||
import { SellerDto } from './dto/seller.dto';
|
||||
import { BillingDto } from './dto/billing.dto';
|
||||
import { CustomerDto } from './dto/customer.dto';
|
||||
import { RegionDto } from './dto/region.dto';
|
||||
import { CarrierDto, FindCarriersDto } from './dto/carrier.dto';
|
||||
|
||||
@ApiTags('DataConsult')
|
||||
@@ -103,4 +104,13 @@ export class DataConsultController {
|
||||
return this.dataConsultService.getOrderCarriers(orderId);
|
||||
}
|
||||
|
||||
@Get('regions')
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
//@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Lista todas as regiões cadastradas' })
|
||||
@ApiResponse({ status: 200, description: 'Lista de regiões retornada com sucesso', type: [RegionDto] })
|
||||
async getRegions(): Promise<RegionDto[]> {
|
||||
return this.dataConsultService.getRegions();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { SellerDto } from './dto/seller.dto';
|
||||
import { BillingDto } from './dto/billing.dto';
|
||||
import { CustomerDto } from './dto/customer.dto';
|
||||
import { ProductDto } from './dto/product.dto';
|
||||
import { RegionDto } from './dto/region.dto';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { DATA_SOURCE } from '../core/constants';
|
||||
|
||||
@@ -217,4 +218,19 @@ async findSellers(): Promise<SellerDto[]> {
|
||||
`;
|
||||
return await this.executeQuery<any[]>(sql, [orderId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca todas as regiões cadastradas
|
||||
*/
|
||||
async findRegions(): Promise<RegionDto[]> {
|
||||
const sql = `
|
||||
SELECT
|
||||
PCREGIAO.NUMREGIAO as "numregiao",
|
||||
PCREGIAO.REGIAO as "regiao"
|
||||
FROM PCREGIAO
|
||||
ORDER BY PCREGIAO.NUMREGIAO
|
||||
`;
|
||||
const results = await this.executeQuery<RegionDto[]>(sql);
|
||||
return results.map(result => new RegionDto(result));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { SellerDto } from './dto/seller.dto';
|
||||
import { BillingDto } from './dto/billing.dto';
|
||||
import { CustomerDto } from './dto/customer.dto';
|
||||
import { ProductDto } from './dto/product.dto';
|
||||
import { RegionDto } from './dto/region.dto';
|
||||
import { CarrierDto, FindCarriersDto } from './dto/carrier.dto';
|
||||
import { ILogger } from '../Log/ILogger';
|
||||
import { RedisClientToken } from '../core/configs/cache/redis-client.adapter.provider';
|
||||
@@ -24,6 +25,8 @@ export class DataConsultService {
|
||||
private readonly CUSTOMERS_TTL = 3600;
|
||||
private readonly CARRIERS_CACHE_KEY = 'data-consult:carriers:all';
|
||||
private readonly CARRIERS_TTL = 3600;
|
||||
private readonly REGIONS_CACHE_KEY = 'data-consult:regions';
|
||||
private readonly REGIONS_TTL = 7200;
|
||||
|
||||
constructor(
|
||||
private readonly repository: DataConsultRepository,
|
||||
@@ -205,4 +208,26 @@ export class DataConsultService {
|
||||
throw new HttpException('Erro ao buscar transportadoras do pedido', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obter todas as regiões cadastradas
|
||||
* @returns Array de RegionDto
|
||||
*/
|
||||
async getRegions(): Promise<RegionDto[]> {
|
||||
this.logger.log('Buscando todas as regiões');
|
||||
try {
|
||||
return getOrSetCache<RegionDto[]>(
|
||||
this.redisClient,
|
||||
this.REGIONS_CACHE_KEY,
|
||||
this.REGIONS_TTL,
|
||||
async () => {
|
||||
const regions = await this.repository.findRegions();
|
||||
return regions;
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error('Erro ao buscar regiões', error);
|
||||
throw new HttpException('Erro ao buscar regiões', HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/data-consult/dto/region.dto.ts
Normal file
23
src/data-consult/dto/region.dto.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
/**
|
||||
* DTO para dados de região
|
||||
*/
|
||||
export class RegionDto {
|
||||
@ApiProperty({
|
||||
description: 'Código da região',
|
||||
example: 1,
|
||||
})
|
||||
numregiao: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Nome/descrição da região',
|
||||
example: 'REGIÃO SUL',
|
||||
})
|
||||
regiao: string;
|
||||
|
||||
constructor(partial: Partial<RegionDto>) {
|
||||
Object.assign(this, partial);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user