ajuste orders
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
HttpStatus,
|
||||
DefaultValuePipe,
|
||||
ParseBoolPipe,
|
||||
Optional,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags, ApiQuery, ApiParam, ApiResponse } from '@nestjs/swagger';
|
||||
import { ResponseInterceptor } from '../../common/response.interceptor';
|
||||
@@ -33,11 +34,13 @@ 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';
|
||||
import { DeliveryCompletedQuery } from '../dto/delivery-completed-query.dto';
|
||||
import { DeliveryCompleted } from '../dto/delivery-completed.dto';
|
||||
|
||||
|
||||
@ApiTags('Orders')
|
||||
//@ApiBearerAuth()
|
||||
//@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('api/v1/orders')
|
||||
export class OrdersController {
|
||||
constructor(private readonly ordersService: OrdersService) {}
|
||||
@@ -48,6 +51,9 @@ export class OrdersController {
|
||||
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: 'includeCompletedDeliveries', required: false, type: 'boolean', description: 'Incluir dados de entregas realizadas para cada pedido' })
|
||||
@ApiQuery({ name: 'limit', required: false, type: 'number', description: 'Limite de registros por página', example: 100 })
|
||||
@ApiQuery({ name: 'offset', required: false, type: 'number', description: 'Offset para paginação', example: 0 })
|
||||
@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)' })
|
||||
@@ -146,10 +152,15 @@ export class OrdersController {
|
||||
@Get('delivery/:orderId')
|
||||
@ApiOperation({ summary: 'Busca dados de entrega do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@ApiQuery({ name: 'includeCompletedDeliveries', required: false, type: 'boolean', description: 'Incluir dados de entregas realizadas para o pedido' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getOrderDelivery(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderDeliveryDto | null> {
|
||||
async getOrderDelivery(
|
||||
@Param('orderId', ParseIntPipe) orderId: number,
|
||||
@Query('includeCompletedDeliveries', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
includeCompletedDeliveries: boolean,
|
||||
): Promise<OrderDeliveryDto | null> {
|
||||
try {
|
||||
return await this.ordersService.getOrderDelivery(orderId.toString());
|
||||
return await this.ordersService.getOrderDelivery(orderId.toString(), includeCompletedDeliveries);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar dados de entrega',
|
||||
@@ -380,4 +391,62 @@ async getTransferLogs(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('completed-deliveries')
|
||||
@ApiOperation({
|
||||
summary: 'Busca entregas realizadas',
|
||||
description: 'Busca entregas realizadas com filtros opcionais por data, cliente, motorista, status e outros critérios.'
|
||||
})
|
||||
@ApiQuery({ name: 'startDate', required: false, type: 'string', description: 'Data de início (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'endDate', required: false, type: 'string', description: 'Data de fim (formato YYYY-MM-DD)' })
|
||||
@ApiQuery({ name: 'outId', required: false, type: 'number', description: 'ID da saída' })
|
||||
@ApiQuery({ name: 'driverName', required: false, type: 'string', description: 'Nome do motorista' })
|
||||
@ApiQuery({ name: 'customerId', required: false, type: 'number', description: 'ID do cliente' })
|
||||
@ApiQuery({ name: 'customerName', required: false, type: 'string', description: 'Nome do cliente' })
|
||||
@ApiQuery({ name: 'orderNumber', required: false, type: 'string', description: 'Número da nota fiscal' })
|
||||
@ApiQuery({ name: 'status', required: false, type: 'string', description: 'Status da entrega' })
|
||||
@ApiQuery({ name: 'limit', required: false, type: 'number', description: 'Limite de registros por página', example: 100 })
|
||||
@ApiQuery({ name: 'offset', required: false, type: 'number', description: 'Offset para paginação', example: 0 })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Entregas realizadas encontradas com sucesso',
|
||||
type: [DeliveryCompleted]
|
||||
})
|
||||
@ApiResponse({ status: 400, description: 'Parâmetros inválidos' })
|
||||
@ApiResponse({ status: 500, description: 'Erro interno do servidor' })
|
||||
async getCompletedDeliveries(
|
||||
@Query('startDate') startDate?: string,
|
||||
@Query('endDate') endDate?: string,
|
||||
@Query('outId') outId?: string,
|
||||
@Query('driverName') driverName?: string,
|
||||
@Query('customerId') customerId?: string,
|
||||
@Query('customerName') customerName?: string,
|
||||
@Query('orderNumber') orderNumber?: string,
|
||||
@Query('status') status?: string,
|
||||
@Query('limit', new DefaultValuePipe(100), ParseIntPipe) limit: number = 100,
|
||||
@Query('offset', new DefaultValuePipe(0), ParseIntPipe) offset: number = 0,
|
||||
) {
|
||||
try {
|
||||
const query: DeliveryCompletedQuery = {
|
||||
startDate,
|
||||
endDate,
|
||||
outId: outId ? parseInt(outId, 10) : undefined,
|
||||
driverName,
|
||||
customerId: customerId ? parseInt(customerId, 10) : undefined,
|
||||
customerName,
|
||||
orderNumber,
|
||||
status,
|
||||
limit,
|
||||
offset,
|
||||
};
|
||||
|
||||
return await this.ordersService.getCompletedDeliveries(query);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar entregas realizadas',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user