first
This commit is contained in:
@@ -11,39 +11,96 @@ import {
|
||||
ValidationPipe,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
DefaultValuePipe,
|
||||
ParseBoolPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags, ApiQuery, ApiParam, ApiResponse } from '@nestjs/swagger';
|
||||
import { ResponseInterceptor } from '../../common/response.interceptor';
|
||||
import { OrdersService } from '../application/orders.service';
|
||||
import { FindOrdersDto } from '../dto/find-orders.dto';
|
||||
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
|
||||
import { FindOrdersByDeliveryDateDto } from '../dto/find-orders-by-delivery-date.dto';
|
||||
import { JwtAuthGuard, } from 'src/auth/guards/jwt-auth.guard';
|
||||
import { InvoiceDto } from '../dto/find-invoice.dto';
|
||||
import { OrderItemDto } from "../dto/OrderItemDto";
|
||||
import { LeadtimeDto } from '../dto/leadtime.dto';
|
||||
import { CutItemDto } from '../dto/CutItemDto';
|
||||
import { OrderDeliveryDto } from '../dto/OrderDeliveryDto';
|
||||
import { OrderTransferDto } from '../dto/OrderTransferDto';
|
||||
import { OrderStatusDto } from '../dto/OrderStatusDto';
|
||||
import { InvoiceCheckDto } from '../dto/invoice-check.dto';
|
||||
|
||||
|
||||
|
||||
import { ParseIntPipe } from '@nestjs/common/pipes/parse-int.pipe';
|
||||
import { CarrierDto } from 'src/data-consult/dto/carrier.dto';
|
||||
import { OrderResponseDto } from '../dto/order-response.dto';
|
||||
import { MarkResponseDto } from '../dto/mark-response.dto';
|
||||
import { EstLogTransferResponseDto } from '../dto/estlogtransfer.dto';
|
||||
|
||||
|
||||
@ApiTags('Orders')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseInterceptors(ResponseInterceptor)
|
||||
//@ApiBearerAuth()
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
@Controller('api/v1/orders')
|
||||
export class OrdersController {
|
||||
constructor(private readonly ordersService: OrdersService) {}
|
||||
|
||||
@Get('find')
|
||||
@ApiOperation({
|
||||
summary: 'Busca pedidos',
|
||||
description: 'Busca pedidos com filtros avançados. Suporta filtros por data, cliente, vendedor, status, tipo de entrega e status de transferência.'
|
||||
})
|
||||
@ApiQuery({ name: 'includeCheckout', required: false, type: 'boolean', description: 'Incluir dados de checkout' })
|
||||
@ApiQuery({ name: 'statusTransfer', required: false, type: 'string', description: 'Filtrar por status de transferência (Em Trânsito, Em Separação, Aguardando Separação, Concluída)' })
|
||||
@ApiQuery({ name: 'markId', required: false, type: 'number', description: 'ID da marca para filtrar pedidos' })
|
||||
@ApiQuery({ name: 'markName', required: false, type: 'string', description: 'Nome da marca para filtrar pedidos (busca parcial)' })
|
||||
@ApiQuery({ name: 'hasPreBox', required: false, type: 'boolean', description: 'Filtrar pedidos que tenham registros na tabela de transfer log' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
findOrders(@Query() query: FindOrdersDto) {
|
||||
@ApiResponse({ status: 200, description: 'Lista de pedidos retornada com sucesso', type: [OrderResponseDto] })
|
||||
findOrders(
|
||||
@Query() query: FindOrdersDto,
|
||||
@Query('includeCheckout', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
includeCheckout: boolean,
|
||||
) {
|
||||
if (includeCheckout) {
|
||||
return this.ordersService.findOrdersWithCheckout(query);
|
||||
}
|
||||
return this.ordersService.findOrders(query);
|
||||
}
|
||||
|
||||
@Get('find-by-delivery-date')
|
||||
@ApiOperation({
|
||||
summary: 'Busca pedidos por data de entrega',
|
||||
description: 'Busca pedidos filtrados por data de entrega. Suporta filtros adicionais como status de transferência, cliente, vendedor, etc.'
|
||||
})
|
||||
@ApiQuery({ name: 'statusTransfer', required: false, type: 'string', description: 'Filtrar por status de transferência (Em Trânsito, Em Separação, Aguardando Separação, Concluída)' })
|
||||
@ApiQuery({ name: 'markId', required: false, type: 'number', description: 'ID da marca para filtrar pedidos' })
|
||||
@ApiQuery({ name: 'markName', required: false, type: 'string', description: 'Nome da marca para filtrar pedidos (busca parcial)' })
|
||||
@ApiQuery({ name: 'hasPreBox', required: false, type: 'boolean', description: 'Filtrar pedidos que tenham registros na tabela de transfer log' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({ status: 200, description: 'Lista de pedidos por data de entrega retornada com sucesso', type: [OrderResponseDto] })
|
||||
findOrdersByDeliveryDate(
|
||||
@Query() query: FindOrdersByDeliveryDateDto,
|
||||
) {
|
||||
return this.ordersService.findOrdersByDeliveryDate(query);
|
||||
}
|
||||
|
||||
@Get(':orderId/checkout')
|
||||
@ApiOperation({ summary: 'Busca fechamento de caixa para um pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
getOrderCheckout(
|
||||
@Param('orderId', ParseIntPipe) orderId: number,
|
||||
) {
|
||||
return this.ordersService.getOrderCheckout(orderId);
|
||||
}
|
||||
|
||||
|
||||
@Get('invoice/:chavenfe')
|
||||
@ApiParam({
|
||||
name: 'chavenfe',
|
||||
required: true,
|
||||
description: 'Chave da Nota Fiscal (44 dígitos)',
|
||||
example: '35191234567890000123550010000000011000000010',
|
||||
})
|
||||
|
||||
@ApiOperation({ summary: 'Busca NF pela chave' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getInvoice(@Param('chavenfe') chavenfe: string): Promise<InvoiceDto> {
|
||||
@@ -56,12 +113,14 @@ export class OrdersController {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('itens/:orderId')
|
||||
@ApiOperation({ summary: 'Busca PELO numero do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getItens(@Param('orderId') orderId: string): Promise<OrderItemDto[]> {
|
||||
async getItens(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderItemDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getItens(orderId);
|
||||
return await this.ordersService.getItens(orderId.toString());
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar itens do pedido',
|
||||
@@ -71,10 +130,11 @@ export class OrdersController {
|
||||
}
|
||||
@Get('cut-itens/:orderId')
|
||||
@ApiOperation({ summary: 'Busca itens cortados do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getCutItens(@Param('orderId') orderId: string): Promise<CutItemDto[]> {
|
||||
async getCutItens(@Param('orderId', ParseIntPipe) orderId: number): Promise<CutItemDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getCutItens(orderId);
|
||||
return await this.ordersService.getCutItens(orderId.toString());
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar itens cortados',
|
||||
@@ -82,13 +142,14 @@ export class OrdersController {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get('delivery/:orderId')
|
||||
@ApiOperation({ summary: 'Busca dados de entrega do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getOrderDelivery(@Param('orderId') orderId: string): Promise<OrderDeliveryDto | null> {
|
||||
async getOrderDelivery(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderDeliveryDto | null> {
|
||||
try {
|
||||
return await this.ordersService.getOrderDelivery(orderId);
|
||||
return await this.ordersService.getOrderDelivery(orderId.toString());
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar dados de entrega',
|
||||
@@ -98,9 +159,10 @@ export class OrdersController {
|
||||
}
|
||||
|
||||
@Get('transfer/:orderId')
|
||||
@ApiOperation({ summary: 'Consulta pedidos de transferência' })
|
||||
@ApiOperation({ summary: 'Consulta pedidos de transferência' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getTransfer(@Param('orderId') orderId: number): Promise<OrderTransferDto[] | null> {
|
||||
async getTransfer(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderTransferDto[] | null> {
|
||||
try {
|
||||
return await this.ordersService.getTransfer(orderId);
|
||||
} catch (error) {
|
||||
@@ -113,8 +175,9 @@ async getTransfer(@Param('orderId') orderId: number): Promise<OrderTransferDto[]
|
||||
|
||||
@Get('status/:orderId')
|
||||
@ApiOperation({ summary: 'Consulta status do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getStatusOrder(@Param('orderId') orderId: number): Promise<OrderStatusDto[] | null> {
|
||||
async getStatusOrder(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderStatusDto[] | null> {
|
||||
try {
|
||||
return await this.ordersService.getStatusOrder(orderId);
|
||||
} catch (error) {
|
||||
@@ -125,6 +188,43 @@ async getStatusOrder(@Param('orderId') orderId: number): Promise<OrderStatusDto[
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get(':orderId/deliveries')
|
||||
@ApiOperation({ summary: 'Consulta entregas do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@ApiQuery({ name: 'createDateIni', required: false, description: 'Data inicial para filtro (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'createDateEnd', required: false, description: 'Data final para filtro (formato YYYY-MM-DD)' })
|
||||
async getOrderDeliveries(
|
||||
@Param('orderId', ParseIntPipe) orderId: number,
|
||||
@Query('createDateIni') createDateIni?: string,
|
||||
@Query('createDateEnd') createDateEnd?: string,
|
||||
): Promise<OrderDeliveryDto[]> {
|
||||
// Definir datas padrão caso não sejam fornecidas
|
||||
const defaultDateIni = createDateIni || new Date(new Date().setDate(new Date().getDate() - 30)).toISOString().split('T')[0];
|
||||
const defaultDateEnd = createDateEnd || new Date().toISOString().split('T')[0];
|
||||
|
||||
return this.ordersService.getOrderDeliveries(orderId.toString(), {
|
||||
createDateIni: defaultDateIni,
|
||||
createDateEnd: defaultDateEnd,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Get('leadtime/:orderId')
|
||||
@ApiOperation({ summary: 'Consulta leadtime do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getLeadtime(@Param('orderId', ParseIntPipe) orderId: number): Promise<LeadtimeDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getLeadtime(orderId.toString());
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar leadtime do pedido',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Post('invoice/check')
|
||||
@ApiOperation({ summary: 'Cria conferência de nota fiscal' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@@ -137,5 +237,147 @@ async createInvoiceCheck(@Body() invoice: InvoiceCheckDto): Promise<{ message: s
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Get('carriers/:orderId')
|
||||
@ApiOperation({ summary: 'Busca transportadoras do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getOrderCarriers(@Param('orderId', ParseIntPipe) orderId: number): Promise<CarrierDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getOrderCarriers(orderId);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar transportadoras do pedido',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('mark/:orderId')
|
||||
@ApiOperation({ summary: 'Busca marca por ID do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({ status: 200, description: 'Marca encontrada com sucesso', type: MarkResponseDto })
|
||||
@ApiResponse({ status: 404, description: 'Marca não encontrada' })
|
||||
async findOrderByMark(@Param('orderId', ParseIntPipe) orderId: number): Promise<MarkResponseDto> {
|
||||
try {
|
||||
return await this.ordersService.findOrderByMark(orderId);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar marca do pedido',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('marks')
|
||||
@ApiOperation({ summary: 'Busca todas as marcas disponíveis' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({ status: 200, description: 'Lista de marcas retornada com sucesso', type: [MarkResponseDto] })
|
||||
async getAllMarks(): Promise<MarkResponseDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getAllMarks();
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar marcas',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('marks/search')
|
||||
@ApiOperation({ summary: 'Busca marcas por nome' })
|
||||
@ApiQuery({ name: 'name', required: true, type: 'string', description: 'Nome da marca para buscar' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({ status: 200, description: 'Lista de marcas encontradas', type: [MarkResponseDto] })
|
||||
async getMarksByName(@Query('name') markName: string): Promise<MarkResponseDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getMarksByName(markName);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar marcas',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('transfer-log/:orderId')
|
||||
@ApiOperation({ summary: 'Busca log de transferência por ID do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 153068638, description: 'ID do pedido para buscar log de transferência' })
|
||||
@ApiQuery({ name: 'dttransf', required: false, type: 'string', description: 'Data de transferência (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'codfilial', required: false, type: 'number', description: 'Código da filial de origem' })
|
||||
@ApiQuery({ name: 'codfilialdest', required: false, type: 'number', description: 'Código da filial de destino' })
|
||||
@ApiQuery({ name: 'numpedloja', required: false, type: 'number', description: 'Número do pedido da loja' })
|
||||
@ApiQuery({ name: 'numpedtransf', required: false, type: 'number', description: 'Número do pedido de transferência' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({ status: 200, description: 'Log de transferência encontrado com sucesso', type: [EstLogTransferResponseDto] })
|
||||
@ApiResponse({ status: 400, description: 'OrderId inválido' })
|
||||
@ApiResponse({ status: 404, description: 'Log de transferência não encontrado' })
|
||||
async getTransferLog(
|
||||
@Param('orderId', ParseIntPipe) orderId: number,
|
||||
@Query('dttransf') dttransf?: string,
|
||||
@Query('codfilial') codfilial?: number,
|
||||
@Query('codfilialdest') codfilialdest?: number,
|
||||
@Query('numpedloja') numpedloja?: number,
|
||||
@Query('numpedtransf') numpedtransf?: number,
|
||||
) {
|
||||
try {
|
||||
const filters = {
|
||||
dttransf,
|
||||
codfilial,
|
||||
codfilialdest,
|
||||
numpedloja,
|
||||
numpedtransf,
|
||||
};
|
||||
|
||||
return await this.ordersService.getTransferLog(orderId, filters);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar log de transferência',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('transfer-log')
|
||||
@ApiOperation({ summary: 'Busca logs de transferência com filtros' })
|
||||
@ApiQuery({ name: 'dttransf', required: false, type: 'string', description: 'Data de transferência (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'dttransfIni', required: false, type: 'string', description: 'Data de transferência inicial (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'dttransfEnd', required: false, type: 'string', description: 'Data de transferência final (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'codfilial', required: false, type: 'number', description: 'Código da filial de origem' })
|
||||
@ApiQuery({ name: 'codfilialdest', required: false, type: 'number', description: 'Código da filial de destino' })
|
||||
@ApiQuery({ name: 'numpedloja', required: false, type: 'number', description: 'Número do pedido da loja' })
|
||||
@ApiQuery({ name: 'numpedtransf', required: false, type: 'number', description: 'Número do pedido de transferência' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({ status: 200, description: 'Logs de transferência encontrados com sucesso', type: [EstLogTransferResponseDto] })
|
||||
@ApiResponse({ status: 400, description: 'Filtros inválidos' })
|
||||
async getTransferLogs(
|
||||
@Query('dttransf') dttransf?: string,
|
||||
@Query('dttransfIni') dttransfIni?: string,
|
||||
@Query('dttransfEnd') dttransfEnd?: string,
|
||||
@Query('codfilial') codfilial?: number,
|
||||
@Query('codfilialdest') codfilialdest?: number,
|
||||
@Query('numpedloja') numpedloja?: number,
|
||||
@Query('numpedtransf') numpedtransf?: number,
|
||||
) {
|
||||
try {
|
||||
const filters = {
|
||||
dttransf,
|
||||
dttransfIni,
|
||||
dttransfEnd,
|
||||
codfilial,
|
||||
codfilialdest,
|
||||
numpedloja,
|
||||
numpedtransf,
|
||||
};
|
||||
|
||||
return await this.ordersService.getTransferLogs(filters);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar logs de transferência',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user