97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import {
|
|
Controller, Get, Post, Body,
|
|
Param,
|
|
UseGuards,
|
|
Query,
|
|
Delete,
|
|
} from '@nestjs/common';
|
|
import { PaymentService } from '../services/payments.service';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiBearerAuth,
|
|
} from '@nestjs/swagger';
|
|
import { UserId } from 'src/common/decorators';
|
|
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
|
|
import { PayOrderDto } from '../dto/pay-order.dto';
|
|
import { FindPaymentsDto } from '../dto/find-payments.dto';
|
|
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
|
|
import { AdminId } from 'src/common/decorators/admin-id.decorator';
|
|
import { Permissions } from 'src/common/decorators/permissions.decorator';
|
|
import { Permission } from 'src/common/enums/permission.enum';
|
|
|
|
@ApiTags('payment')
|
|
@ApiBearerAuth()
|
|
@Controller()
|
|
export class PaymentController {
|
|
constructor(
|
|
private readonly paymentService: PaymentService,
|
|
) { }
|
|
|
|
|
|
@Post('public/payments/order/:id/pay')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Pay for an order' })
|
|
payAnOrder(@Param('id') orderId: string, @Body() dto: PayOrderDto) {
|
|
return this.paymentService.payOrder(orderId, dto);
|
|
}
|
|
|
|
@Post('public/payments/online/:token/verify')
|
|
@UseGuards(AuthGuard)
|
|
@ApiOperation({ summary: 'Verify online payment' })
|
|
verifyOnlinePayment(@Param('paymentId') token: string) {
|
|
return this.paymentService.verifyOnlinePayment(token);
|
|
}
|
|
|
|
|
|
@Get('public/payments')
|
|
@ApiOperation({ summary: 'get all payments as user' })
|
|
findAllByUser(@UserId() userId: string, @Query() dto: FindPaymentsDto) {
|
|
return this.paymentService.findAllByUser(dto, userId);
|
|
}
|
|
|
|
/*=============== Admin =============== */
|
|
|
|
@Post('admin/payments/order/:id/pay')
|
|
@UseGuards(AdminAuthGuard)
|
|
@Permissions(Permission.MANAGE_PAYMENTS)
|
|
@ApiOperation({ summary: 'Pay for an order as Admin' })
|
|
payOrderAsAdmin(@Param('orderId') orderId: string, @AdminId() adminId: string, @Body() dto: PayOrderDto) {
|
|
return this.paymentService.payOrder(orderId, dto, adminId);
|
|
}
|
|
|
|
@Post('admin/payments/online/:token/verify')
|
|
@UseGuards(AdminAuthGuard)
|
|
@Permissions(Permission.MANAGE_PAYMENTS)
|
|
@ApiOperation({ summary: 'Verify online payment as admin' })
|
|
verifyOnlinePaymentAsAdmin(@Param('paymentId') token: string) {
|
|
return this.paymentService.verifyOnlinePayment(token);
|
|
}
|
|
|
|
@Post('admin/payments/:paymentId/cash/verify')
|
|
@UseGuards(AdminAuthGuard)
|
|
@Permissions(Permission.MANAGE_PAYMENTS)
|
|
@ApiOperation({ summary: 'Verify cash payment' })
|
|
confirmPayment(@Param('paymentId') paymentId: string) {
|
|
return this.paymentService.confirmCashPayment(paymentId);
|
|
}
|
|
|
|
@Delete('admin/payments/:paymentId/cash/deny')
|
|
@UseGuards(AdminAuthGuard)
|
|
@Permissions(Permission.MANAGE_PAYMENTS)
|
|
@ApiOperation({ summary: 'Deny cash payment' })
|
|
denyPayment(@Param('paymentId') paymentId: string) {
|
|
return this.paymentService.denyCashPayment(paymentId);
|
|
}
|
|
|
|
|
|
@Get('admin/payments')
|
|
@UseGuards(AdminAuthGuard)
|
|
@Permissions(Permission.MANAGE_PAYMENTS)
|
|
@ApiOperation({ summary: 'get all payments as admin' })
|
|
findAllPayments(@Body() dto: FindPaymentsDto) {
|
|
return this.paymentService.findAll(dto);
|
|
}
|
|
|
|
}
|