This commit is contained in:
2025-11-25 16:11:00 +03:30
parent e6fb28b87e
commit c2bd8b94e5
5 changed files with 126 additions and 123 deletions
@@ -1,29 +0,0 @@
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { PaymentMethodService } from '../services/payment-method.service';
import { ApiTags, ApiOperation, ApiOkResponse, ApiNotFoundResponse, ApiParam, ApiBearerAuth } from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiTags('admin/payment-methods')
@Controller('admin/payment-methods')
export class PaymentMethodController {
constructor(private readonly paymentMethodService: PaymentMethodService) {}
@Get()
@ApiOperation({ summary: 'Get all payment methods' })
@ApiOkResponse({ description: 'List of all payment methods' })
findAll() {
return this.paymentMethodService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get a payment method by ID' })
@ApiParam({ name: 'id', type: 'string', description: 'Payment method ID' })
@ApiOkResponse({ description: 'Payment method found' })
@ApiNotFoundResponse({ description: 'Payment method not found' })
findOne(@Param('id') id: string) {
return this.paymentMethodService.findOne(id);
}
}
@@ -5,7 +5,6 @@ import { UpdatePaymentDto } from '../dto/update-payment.dto';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiCreatedResponse,
ApiOkResponse,
ApiNotFoundResponse,
@@ -14,55 +13,158 @@ import {
ApiBearerAuth,
} from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { PaymentMethodService } from '../services/payment-method.service';
import { RestaurantPaymentMethodService } from '../services/restaurant-payment-method.service';
import { CreateRestaurantPaymentMethodDto } from '../dto/create-restaurant-payment-method.dto';
import { UpdateRestaurantPaymentMethodDto } from '../dto/update-restaurant-payment-method.dto';
import { RestId } from 'src/common/decorators';
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiTags('admin/payments')
@Controller('admin/payments')
@ApiTags('payments')
@Controller()
export class PaymentsController {
constructor(private readonly paymentsService: PaymentsService) {}
constructor(
private readonly paymentsService: PaymentsService,
private readonly paymentMethodService: PaymentMethodService,
private readonly restaurantPaymentMethodService: RestaurantPaymentMethodService,
) {}
@Post()
@UseGuards(AuthGuard)
@ApiBearerAuth()
@Get('public/payments/methods/restaurant')
@ApiOperation({ summary: 'Get the restaurant payment methods' })
@ApiNotFoundResponse({ description: 'Restaurant payment methods not found' })
getTheRestaurantPaymentMethods(@RestId() restId: string) {
return this.restaurantPaymentMethodService.findByRestaurant(restId);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Post('admin/payments')
@ApiOperation({ summary: 'Create a new payment' })
@ApiBody({ type: CreatePaymentDto })
@ApiCreatedResponse({ description: 'Payment created successfully' })
create(@Body() createPaymentDto: CreatePaymentDto) {
createPayment(@Body() createPaymentDto: CreatePaymentDto) {
return this.paymentsService.create(createPaymentDto);
}
@Get()
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/payments')
@ApiOperation({ summary: 'Get all payments' })
@ApiOkResponse({ description: 'List of all payments' })
findAll() {
findAllPayments() {
return this.paymentsService.findAll();
}
@Get(':id')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/payments/:id')
@ApiOperation({ summary: 'Get a payment by ID' })
@ApiParam({ name: 'id', type: 'number', description: 'Payment ID' })
@ApiOkResponse({ description: 'Payment found' })
@ApiNotFoundResponse({ description: 'Payment not found' })
findOne(@Param('id') id: string) {
findOnePayment(@Param('id') id: string) {
return this.paymentsService.findOne(+id);
}
@Patch(':id')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Patch('admin/payments/:id')
@ApiOperation({ summary: 'Update a payment' })
@ApiParam({ name: 'id', type: 'number', description: 'Payment ID' })
@ApiBody({ type: UpdatePaymentDto })
@ApiOkResponse({ description: 'Payment updated successfully' })
@ApiNotFoundResponse({ description: 'Payment not found' })
update(@Param('id') id: string, @Body() updatePaymentDto: UpdatePaymentDto) {
updatePayment(@Param('id') id: string, @Body() updatePaymentDto: UpdatePaymentDto) {
return this.paymentsService.update(+id, updatePaymentDto);
}
@Delete(':id')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Delete('admin/payments/:id')
@ApiOperation({ summary: 'Delete a payment' })
@ApiParam({ name: 'id', type: 'number', description: 'Payment ID' })
@ApiOkResponse({ description: 'Payment deleted successfully' })
@ApiNotFoundResponse({ description: 'Payment not found' })
remove(@Param('id') id: string) {
removePayment(@Param('id') id: string) {
return this.paymentsService.remove(+id);
}
}
/** payment methods */
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/payments/methods')
@ApiOperation({ summary: 'Get all payment methods' })
@ApiOkResponse({ description: 'List of all payment methods' })
findAll() {
return this.paymentMethodService.findAll();
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/payments/methods/:id')
@ApiOperation({ summary: 'Get a payment method by ID' })
@ApiParam({ name: 'id', type: 'string', description: 'Payment method ID' })
@ApiOkResponse({ description: 'Payment method found' })
@ApiNotFoundResponse({ description: 'Payment method not found' })
findOne(@Param('id') id: string) {
return this.paymentMethodService.findOne(id);
}
/** restaurant payment methods */
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Post('admin/payments/methods/restaurant')
@ApiOperation({ summary: 'Create a new restaurant payment method' })
@ApiBody({ type: CreateRestaurantPaymentMethodDto })
@ApiCreatedResponse({ description: 'Restaurant payment method created successfully' })
create(@RestId() restId: string, @Body() createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto) {
return this.restaurantPaymentMethodService.create(restId, createRestaurantPaymentMethodDto);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/payments/methods/restaurant/:restaurantPaymentMethodId')
@ApiOperation({ summary: 'Get restaurant payment method by payment method ID' })
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'restaurantPaymentMethodId method ID' })
@ApiOkResponse({ description: 'List of restaurant payment methods for the payment method' })
findByPaymentMethod(@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string) {
return this.restaurantPaymentMethodService.findByPaymentMethod(restaurantPaymentMethodId);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/payments/methods/restaurant')
@ApiOperation({ summary: 'Get restaurant all payment methods ' })
@ApiOkResponse({ description: 'Restaurant payment method found' })
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
findByRestaurant(@RestId() restId: string) {
return this.restaurantPaymentMethodService.findByRestaurant(restId);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Patch('admin/payments/methods/restaurant/:restaurantPaymentMethodId')
@ApiOperation({ summary: 'Update a restaurant payment method' })
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'Restaurant payment method ID' })
@ApiBody({ type: UpdateRestaurantPaymentMethodDto })
@ApiOkResponse({ description: 'Restaurant payment method updated successfully' })
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
update(
@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string,
@Body() updateRestaurantPaymentMethodDto: UpdateRestaurantPaymentMethodDto,
) {
return this.restaurantPaymentMethodService.update(restaurantPaymentMethodId, updateRestaurantPaymentMethodDto);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Delete('admin/payments/methods/restaurant/:restaurantPaymentMethodId')
@ApiOperation({ summary: 'Delete a restaurant payment method' })
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'Restaurant payment method ID' })
@ApiOkResponse({ description: 'Restaurant payment method deleted successfully' })
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
remove(@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string) {
return this.restaurantPaymentMethodService.remove(restaurantPaymentMethodId);
}
}
@@ -1,70 +0,0 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
import { RestaurantPaymentMethodService } from '../services/restaurant-payment-method.service';
import { CreateRestaurantPaymentMethodDto } from '../dto/create-restaurant-payment-method.dto';
import { UpdateRestaurantPaymentMethodDto } from '../dto/update-restaurant-payment-method.dto';
import { RestId } from 'src/common/decorators/rest-id.decorator';
import {
ApiTags,
ApiOperation,
ApiCreatedResponse,
ApiOkResponse,
ApiNotFoundResponse,
ApiBody,
ApiParam,
ApiBearerAuth,
} from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiTags('admin/restaurant-payment-methods')
@Controller('admin/restaurant-payment-methods')
export class RestaurantPaymentMethodController {
constructor(private readonly restaurantPaymentMethodService: RestaurantPaymentMethodService) {}
@Post()
@ApiOperation({ summary: 'Create a new restaurant payment method' })
@ApiBody({ type: CreateRestaurantPaymentMethodDto })
@ApiCreatedResponse({ description: 'Restaurant payment method created successfully' })
create(@RestId() restId: string, @Body() createRestaurantPaymentMethodDto: CreateRestaurantPaymentMethodDto) {
return this.restaurantPaymentMethodService.create(restId, createRestaurantPaymentMethodDto);
}
@Get(':restaurantPaymentMethodId')
@ApiOperation({ summary: 'Get restaurant payment method by payment method ID' })
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'restaurantPaymentMethodId method ID' })
@ApiOkResponse({ description: 'List of restaurant payment methods for the payment method' })
findByPaymentMethod(@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string) {
return this.restaurantPaymentMethodService.findByPaymentMethod(restaurantPaymentMethodId);
}
@Get()
@ApiOperation({ summary: 'Get restaurant all payment methods ' })
@ApiOkResponse({ description: 'Restaurant payment method found' })
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
findByRestaurant(@RestId() restId: string) {
return this.restaurantPaymentMethodService.findByRestaurant(restId);
}
@Patch(':restaurantPaymentMethodId')
@ApiOperation({ summary: 'Update a restaurant payment method' })
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'Restaurant payment method ID' })
@ApiBody({ type: UpdateRestaurantPaymentMethodDto })
@ApiOkResponse({ description: 'Restaurant payment method updated successfully' })
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
update(
@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string,
@Body() updateRestaurantPaymentMethodDto: UpdateRestaurantPaymentMethodDto,
) {
return this.restaurantPaymentMethodService.update(restaurantPaymentMethodId, updateRestaurantPaymentMethodDto);
}
@Delete(':restaurantPaymentMethodId')
@ApiOperation({ summary: 'Delete a restaurant payment method' })
@ApiParam({ name: 'restaurantPaymentMethodId', type: 'string', description: 'Restaurant payment method ID' })
@ApiOkResponse({ description: 'Restaurant payment method deleted successfully' })
@ApiNotFoundResponse({ description: 'Restaurant payment method not found' })
remove(@Param('restaurantPaymentMethodId') restaurantPaymentMethodId: string) {
return this.restaurantPaymentMethodService.remove(restaurantPaymentMethodId);
}
}
+1 -3
View File
@@ -9,14 +9,12 @@ import { RestaurantPaymentMethodRepository } from './repositories/restaurant-pay
import { RestaurantPaymentMethodService } from './services/restaurant-payment-method.service';
import { Restaurant } from '../restaurants/entities/restaurant.entity';
import { PaymentsController } from './controllers/payments.controller';
import { PaymentMethodController } from './controllers/payment-method.controller';
import { RestaurantPaymentMethodController } from './controllers/restaurant-payment-method.controller';
import { AuthModule } from '../auth/auth.module';
import { JwtModule } from '@nestjs/jwt';
@Module({
imports: [MikroOrmModule.forFeature([PaymentMethod, RestaurantPaymentMethod, Restaurant]), AuthModule, JwtModule],
controllers: [PaymentsController, PaymentMethodController, RestaurantPaymentMethodController],
controllers: [PaymentsController],
providers: [
PaymentsService,
PaymentMethodService,
@@ -36,10 +36,12 @@ export class RestaurantsController {
create(@Body() createRestaurantDto: CreateRestaurantDto) {
return this.restaurantsService.create(createRestaurantDto);
}
@Get('admin/restaurants')
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get all restaurants' })
@ApiResponse({ status: 200, description: 'Restaurants found' })
@Get()
findAll() {
return this.restaurantsService.findAll();
}
@@ -50,7 +52,7 @@ export class RestaurantsController {
@ApiOperation({ summary: 'Get restaurant by ID from request' })
@ApiResponse({ status: 200, description: 'Restaurant found' })
@ApiNotFoundResponse({ description: 'Restaurant not found' })
@Get('my-restaurant')
@Get('admin/restaurants/my-restaurant')
async findOne(@RestId() restId: string) {
return await this.restaurantsService.findOne(restId);
}