impl modulo orde node 22
This commit is contained in:
76
src/orders/controllers/orders.controller.ts
Normal file
76
src/orders/controllers/orders.controller.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Query,
|
||||
UsePipes,
|
||||
UseGuards,
|
||||
UseInterceptors,
|
||||
ValidationPipe,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } 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 { InvoiceDto } from '../dto/find-invoice.dto';
|
||||
import { OrderItemDto } from "../dto/OrderItemDto";
|
||||
import { CutItemDto } from '../dto/CutItemDto';
|
||||
|
||||
|
||||
@ApiTags('Orders')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseInterceptors(ResponseInterceptor)
|
||||
@Controller('api/v1/orders')
|
||||
export class OrdersController {
|
||||
constructor(private readonly ordersService: OrdersService) {}
|
||||
|
||||
@Get('find')
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
findOrders(@Query() query: FindOrdersDto) {
|
||||
return this.ordersService.findOrders(query);
|
||||
}
|
||||
|
||||
@Get('invoice/:chavenfe')
|
||||
@ApiOperation({ summary: 'Busca NF pela chave' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getInvoice(@Param('chavenfe') chavenfe: string): Promise<InvoiceDto> {
|
||||
try {
|
||||
return await this.ordersService.findInvoice(chavenfe);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar nota fiscal',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@Get('itens/:orderId')
|
||||
@ApiOperation({ summary: 'Busca PELO numero do pedido' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getItens(@Param('orderId') orderId: string): Promise<OrderItemDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getItens(orderId);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar itens do pedido',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@Get('cut-itens/:orderId')
|
||||
@ApiOperation({ summary: 'Busca itens cortados do pedido' })
|
||||
@UsePipes(new ValidationPipe({ transform: true }))
|
||||
async getCutItens(@Param('orderId') orderId: string): Promise<CutItemDto[]> {
|
||||
try {
|
||||
return await this.ordersService.getCutItens(orderId);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Erro ao buscar itens cortados',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user