payment permission

This commit is contained in:
2026-02-01 12:41:50 +03:30
parent f452fa0d11
commit 918d774cad
@@ -17,79 +17,80 @@ import { PayOrderDto } from '../dto/pay-order.dto';
import { FindPaymentsDto } from '../dto/find-payments.dto'; import { FindPaymentsDto } from '../dto/find-payments.dto';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { AdminId } from 'src/common/decorators/admin-id.decorator'; 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') @ApiTags('payment')
@ApiBearerAuth()
@Controller() @Controller()
export class PaymentController { export class PaymentController {
constructor( constructor(
private readonly paymentsService: PaymentService, private readonly paymentService: PaymentService,
) { } ) { }
@Post('public/payments/pay-order/:orderId') @Post('public/payments/order/:id/pay')
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Pay for an order' }) @ApiOperation({ summary: 'Pay for an order' })
payAnOrder(@Param('orderId') orderId: string, @Body() dto: PayOrderDto) { payAnOrder(@Param('id') orderId: string, @Body() dto: PayOrderDto) {
return this.paymentsService.payOrder(orderId, dto); return this.paymentService.payOrder(orderId, dto);
} }
@Post('public/payments/:token/verify/online') @Post('public/payments/online/:token/verify')
@UseGuards(AuthGuard) @UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Verify online payment' }) @ApiOperation({ summary: 'Verify online payment' })
verifyOnlinePayment(@Param('paymentId') token: string) { verifyOnlinePayment(@Param('paymentId') token: string) {
return this.paymentsService.verifyOnlinePayment(token); return this.paymentService.verifyOnlinePayment(token);
} }
@ApiBearerAuth()
@Get('public/payments') @Get('public/payments')
@ApiOperation({ summary: 'get all payments as user' }) @ApiOperation({ summary: 'get all payments as user' })
findAllByUser(@UserId() userId: string, @Query() dto: FindPaymentsDto) { findAllByUser(@UserId() userId: string, @Query() dto: FindPaymentsDto) {
return this.paymentsService.findAllByUser(dto, userId); return this.paymentService.findAllByUser(dto, userId);
} }
/*=============== Admin =============== */ /*=============== Admin =============== */
@Post('admin/payments/pay-order/:orderId') @Post('admin/payments/order/:id/pay')
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @Permissions(Permission.MANAGE_PAYMENTS)
@ApiOperation({ summary: 'Pay for an order as Admin' }) @ApiOperation({ summary: 'Pay for an order as Admin' })
payOrderAsAdmin(@Param('orderId') orderId: string, @AdminId() adminId: string, @Body() dto: PayOrderDto) { payOrderAsAdmin(@Param('orderId') orderId: string, @AdminId() adminId: string, @Body() dto: PayOrderDto) {
return this.paymentsService.payOrder(orderId, dto, adminId); return this.paymentService.payOrder(orderId, dto, adminId);
} }
@Post('admin/payments/:token/verify/online') @Post('admin/payments/online/:token/verify')
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @Permissions(Permission.MANAGE_PAYMENTS)
@ApiOperation({ summary: 'Verify online payment as admin' }) @ApiOperation({ summary: 'Verify online payment as admin' })
verifyOnlinePaymentAsAdmin(@Param('paymentId') token: string) { verifyOnlinePaymentAsAdmin(@Param('paymentId') token: string) {
return this.paymentsService.verifyOnlinePayment(token); return this.paymentService.verifyOnlinePayment(token);
} }
@Post('admin/payments/:paymentId/verify/cash') @Post('admin/payments/:paymentId/cash/verify')
@UseGuards(AuthGuard) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @Permissions(Permission.MANAGE_PAYMENTS)
@ApiOperation({ summary: 'Verify cash payment' }) @ApiOperation({ summary: 'Verify cash payment' })
confirmPayment(@Param('paymentId') paymentId: string) { confirmPayment(@Param('paymentId') paymentId: string) {
return this.paymentsService.confirmCashPayment(paymentId); return this.paymentService.confirmCashPayment(paymentId);
} }
@Delete('admin/payments/:paymentId/verify/cash') @Delete('admin/payments/:paymentId/cash/deny')
@UseGuards(AuthGuard) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @Permissions(Permission.MANAGE_PAYMENTS)
@ApiOperation({ summary: 'Deny cash payment' }) @ApiOperation({ summary: 'Deny cash payment' })
denyPayment(@Param('paymentId') paymentId: string) { denyPayment(@Param('paymentId') paymentId: string) {
return this.paymentsService.denyCashPayment(paymentId); return this.paymentService.denyCashPayment(paymentId);
} }
// @UseGuards(AdminAuthGuard)
// @Permissions(Permission.MANAGE_PAYMENTS)
@ApiBearerAuth()
@Get('admin/payments') @Get('admin/payments')
@UseGuards(AdminAuthGuard)
@Permissions(Permission.MANAGE_PAYMENTS)
@ApiOperation({ summary: 'get all payments as admin' }) @ApiOperation({ summary: 'get all payments as admin' })
findAllPayments(@Body() dto: FindPaymentsDto) { findAllPayments(@Body() dto: FindPaymentsDto) {
return this.paymentsService.findAll(dto); return this.paymentService.findAll(dto);
} }
} }