feat: suporte a múltiplos sellerId e melhorias no código
- Adicionado suporte para sellerId como string separada por vírgula (ex: 270,431) - Melhorias em deb.repository: tipagem e documentação - Melhorias em deb.service: remoção de validação redundante - Melhorias em deb.controller: remoção de try/catch duplicado - Melhorias em orders.service: early returns e tipagem melhorada - Aplicado early returns para reduzir aninhamento - Melhorias de tipagem em todos os métodos
This commit is contained in:
@@ -1,49 +1,46 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
UsePipes,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags, ApiResponse } from '@nestjs/swagger';
|
||||
import { DebService } from '../application/deb.service';
|
||||
import { DebDto } from '../dto/DebDto';
|
||||
import { FindDebDto } from '../dto/find-deb.dto';
|
||||
|
||||
@ApiTags('Débitos')
|
||||
@Controller('api/v1/deb')
|
||||
export class DebController {
|
||||
constructor(private readonly debService: DebService) {}
|
||||
|
||||
@Get('find-by-cpf')
|
||||
@ApiOperation({
|
||||
summary: 'Busca débitos por CPF/CGCENT',
|
||||
description: 'Busca débitos de um cliente usando CPF ou CGCENT. Opcionalmente pode filtrar por matrícula do funcionário ou código de cobrança.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Lista de débitos retornada com sucesso',
|
||||
type: [DebDto],
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'CPF/CGCENT é obrigatório',
|
||||
})
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async findByCpfCgcent(
|
||||
@Query() query: FindDebDto,
|
||||
): Promise<DebDto[]> {
|
||||
try {
|
||||
return await this.debService.findByCpfCgcent(query.cpfCgcent, query.matricula, query.cobranca);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar débitos',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
Controller,
|
||||
Get,
|
||||
Query,
|
||||
UsePipes,
|
||||
ValidationPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiOperation, ApiTags, ApiResponse } from '@nestjs/swagger';
|
||||
import { DebService } from '../application/deb.service';
|
||||
import { DebDto } from '../dto/DebDto';
|
||||
import { FindDebDto } from '../dto/find-deb.dto';
|
||||
|
||||
@ApiTags('Débitos')
|
||||
@Controller('api/v1/deb')
|
||||
export class DebController {
|
||||
constructor(private readonly debService: DebService) {}
|
||||
|
||||
@Get('find-by-cpf')
|
||||
@ApiOperation({
|
||||
summary: 'Busca débitos por CPF/CGCENT',
|
||||
description: 'Busca débitos de um cliente usando CPF ou CGCENT. Opcionalmente pode filtrar por matrícula do funcionário ou código de cobrança.',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Lista de débitos retornada com sucesso',
|
||||
type: [DebDto],
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 400,
|
||||
description: 'CPF/CGCENT é obrigatório',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 500,
|
||||
description: 'Erro interno do servidor',
|
||||
})
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async findByCpfCgcent(
|
||||
@Query() query: FindDebDto,
|
||||
): Promise<DebDto[]> {
|
||||
return await this.debService.findByCpfCgcent(
|
||||
query.cpfCgcent,
|
||||
query.matricula,
|
||||
query.cobranca,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
HttpStatus,
|
||||
DefaultValuePipe,
|
||||
ParseBoolPipe,
|
||||
Optional,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags, ApiQuery, ApiParam, ApiResponse } from '@nestjs/swagger';
|
||||
import { ResponseInterceptor } from '../../common/response.interceptor';
|
||||
@@ -34,8 +33,6 @@ 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')
|
||||
@@ -51,9 +48,6 @@ 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)' })
|
||||
@@ -90,7 +84,7 @@ export class OrdersController {
|
||||
|
||||
@Get(':orderId/checkout')
|
||||
@ApiOperation({ summary: 'Busca fechamento de caixa para um pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
getOrderCheckout(
|
||||
@Param('orderId', ParseIntPipe) orderId: number,
|
||||
@@ -104,7 +98,6 @@ export class OrdersController {
|
||||
name: 'chavenfe',
|
||||
required: true,
|
||||
description: 'Chave da Nota Fiscal (44 dígitos)',
|
||||
example: '35191234567890000123550010000000011000000010',
|
||||
})
|
||||
|
||||
@ApiOperation({ summary: 'Busca NF pela chave' })
|
||||
@@ -122,7 +115,7 @@ export class OrdersController {
|
||||
|
||||
@Get('itens/:orderId')
|
||||
@ApiOperation({ summary: 'Busca PELO numero do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getItens(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderItemDto[]> {
|
||||
try {
|
||||
@@ -136,7 +129,7 @@ export class OrdersController {
|
||||
}
|
||||
@Get('cut-itens/:orderId')
|
||||
@ApiOperation({ summary: 'Busca itens cortados do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getCutItens(@Param('orderId', ParseIntPipe) orderId: number): Promise<CutItemDto[]> {
|
||||
try {
|
||||
@@ -151,16 +144,11 @@ 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' })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getOrderDelivery(
|
||||
@Param('orderId', ParseIntPipe) orderId: number,
|
||||
@Query('includeCompletedDeliveries', new DefaultValuePipe(false), ParseBoolPipe)
|
||||
includeCompletedDeliveries: boolean,
|
||||
): Promise<OrderDeliveryDto | null> {
|
||||
async getOrderDelivery(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderDeliveryDto | null> {
|
||||
try {
|
||||
return await this.ordersService.getOrderDelivery(orderId.toString(), includeCompletedDeliveries);
|
||||
return await this.ordersService.getOrderDelivery(orderId.toString());
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar dados de entrega',
|
||||
@@ -171,7 +159,7 @@ export class OrdersController {
|
||||
|
||||
@Get('transfer/:orderId')
|
||||
@ApiOperation({ summary: 'Consulta pedidos de transferência' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getTransfer(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderTransferDto[] | null> {
|
||||
try {
|
||||
@@ -186,7 +174,7 @@ export class OrdersController {
|
||||
|
||||
@Get('status/:orderId')
|
||||
@ApiOperation({ summary: 'Consulta status do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: 236001388 })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getStatusOrder(@Param('orderId', ParseIntPipe) orderId: number): Promise<OrderStatusDto[] | null> {
|
||||
try {
|
||||
@@ -202,7 +190,7 @@ export class OrdersController {
|
||||
|
||||
@Get(':orderId/deliveries')
|
||||
@ApiOperation({ summary: 'Consulta entregas do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@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(
|
||||
@@ -223,7 +211,7 @@ export class OrdersController {
|
||||
|
||||
@Get('leadtime/:orderId')
|
||||
@ApiOperation({ summary: 'Consulta leadtime do pedido' })
|
||||
@ApiParam({ name: 'orderId', example: '236001388' })
|
||||
@ApiParam({ name: 'orderId' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getLeadtime(@Param('orderId', ParseIntPipe) orderId: number): Promise<LeadtimeDto[]> {
|
||||
try {
|
||||
@@ -315,7 +303,7 @@ async getMarksByName(@Query('name') markName: string): Promise<MarkResponseDto[]
|
||||
|
||||
@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' })
|
||||
@ApiParam({ name: 'orderId', 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' })
|
||||
@@ -391,62 +379,4 @@ 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