83 lines
2.6 KiB
TypeScript
83 lines
2.6 KiB
TypeScript
import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiParam,
|
|
ApiResponse,
|
|
ApiBearerAuth,
|
|
} from '@nestjs/swagger';
|
|
import { OrdersPaymentService } from './orders-payment.service';
|
|
import { OrderDto } from './dto/order.dto';
|
|
import { PaymentDto } from './dto/payment.dto';
|
|
import { CreatePaymentDto } from './dto/create-payment.dto';
|
|
import { CreateInvoiceDto } from './dto/create-invoice.dto';
|
|
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
|
|
|
|
@ApiTags('Orders Payment')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('api/v1/orders-payment')
|
|
export class OrdersPaymentController {
|
|
constructor(private readonly orderPaymentService: OrdersPaymentService) {}
|
|
|
|
@Get('orders/:id')
|
|
@ApiOperation({ summary: 'Lista todos os pedidos de uma loja' })
|
|
@ApiParam({ name: 'id', description: 'ID da loja' })
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'Lista de pedidos retornada com sucesso',
|
|
type: [OrderDto],
|
|
})
|
|
async findOrders(@Param('id') storeId: string): Promise<OrderDto[]> {
|
|
return this.orderPaymentService.findOrders(storeId, 0);
|
|
}
|
|
|
|
@Get('orders/:id/:orderId')
|
|
@ApiOperation({ summary: 'Busca um pedido específico' })
|
|
@ApiParam({ name: 'id', description: 'ID da loja' })
|
|
@ApiParam({ name: 'orderId', description: 'ID do pedido' })
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'Pedido retornado com sucesso',
|
|
type: OrderDto,
|
|
})
|
|
async findOrder(
|
|
@Param('id') storeId: string,
|
|
@Param('orderId') orderId: number,
|
|
): Promise<OrderDto> {
|
|
const orders = await this.orderPaymentService.findOrders(storeId, orderId);
|
|
return orders[0];
|
|
}
|
|
|
|
@Get('payments/:id')
|
|
@ApiOperation({ summary: 'Lista todos os pagamentos de um pedido' })
|
|
@ApiParam({ name: 'id', description: 'ID do pedido' })
|
|
@ApiResponse({
|
|
status: 200,
|
|
description: 'Lista de pagamentos retornada com sucesso',
|
|
type: [PaymentDto],
|
|
})
|
|
async findPayments(@Param('id') orderId: number): Promise<PaymentDto[]> {
|
|
return this.orderPaymentService.findPayments(orderId);
|
|
}
|
|
@Post('payments/create')
|
|
@ApiOperation({ summary: 'Cria um novo pagamento' })
|
|
@ApiResponse({
|
|
status: 201,
|
|
description: 'Pagamento criado com sucesso',
|
|
})
|
|
async createPayment(@Body() data: CreatePaymentDto): Promise<void> {
|
|
return this.orderPaymentService.createPayment(data);
|
|
}
|
|
|
|
@Post('invoice/create')
|
|
@ApiOperation({ summary: 'Cria uma nova fatura' })
|
|
@ApiResponse({
|
|
status: 201,
|
|
description: 'Fatura criada com sucesso',
|
|
})
|
|
async createInvoice(@Body() data: CreateInvoiceDto): Promise<void> {
|
|
return this.orderPaymentService.createInvoice(data);
|
|
}
|
|
}
|