This commit is contained in:
2025-12-06 09:02:03 +03:30
parent 683406a396
commit 83829856ad
4 changed files with 17 additions and 18 deletions
+11 -2
View File
@@ -4,6 +4,7 @@ import { OrdersService } from './orders.service';
import { AuthGuard } from '../auth/guards/auth.guard';
import { UserId } from '../../common/decorators/user-id.decorator';
import { RestId } from 'src/common/decorators/rest-id.decorator';
import { AdminAuthGuard } from '../auth/guards/adminAuth.guard';
@ApiTags('orders')
@Controller()
@@ -22,8 +23,16 @@ export class OrdersController {
@ApiBearerAuth()
@Get('public/orders')
@ApiOperation({ summary: 'Get all orders' })
findAll() {
return this.ordersService.findAll();
findAll(@RestId() restId: string) {
return this.ordersService.findAll(restId);
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Get('admin/orders')
@ApiOperation({ summary: 'Get all orders' })
findAllAdmin(@RestId() restId: string) {
return this.ordersService.findAll(restId);
}
@UseGuards(AuthGuard)
+3 -3
View File
@@ -37,7 +37,7 @@ export class OrdersService {
throw new BadRequestException('Payment method is required for checkout');
}
const { paymentUrl } = await this.paymentsService.initializePayment(order.paymentMethod.id, order.total, order.id);
const { paymentUrl } = await this.paymentsService.startPayment(order.id);
await this.cartService.clearCart(userId, restaurantId);
@@ -234,10 +234,10 @@ export class OrdersService {
};
}
async findAll() {
async findAll(restId: string) {
const orders = await this.em.find(
Order,
{},
{ restaurant: { id: restId } },
{ populate: ['user', 'restaurant', 'deliveryMethod', 'address', 'paymentMethod'] },
);
if (!orders) {
@@ -26,14 +26,7 @@ export class PaymentsController {
return this.paymentMethodService.findByRestaurant(restId);
}
@UseGuards(AuthGuard)
@ApiBearerAuth()
@Get('public/payments/methods/restaurant')
@ApiOperation({ summary: 'Get the restaurant payment methods' })
@ApiNotFoundResponse({ description: 'Restaurant payment methods not found' })
payOrder(@RestId() restId: string) {
return this.paymentMethodService.findByRestaurant(restId);
}
// @UseGuards(AdminAuthGuard)
// @ApiBearerAuth()
@@ -55,9 +55,6 @@ export class PaymentsService {
// return { paymentUrl };
// }
asynv paymentGatewayAuthorize(amount: number, orderId: string, merchantId: string, gateway: PaymentGatewayEnum){
}
async startPayment(orderId: string): Promise<{ paymentUrl: string | null }> {
const { amount, method, restaurantDomain, gateway, merchantId } = await this.validateOrder(orderId);
@@ -105,10 +102,10 @@ export class PaymentsService {
}
async createPayment(domain: string, dto: CreatePaymentDto) {
const { amount, orderId, merchantId, gateway, paymentMethod } = dto;
const { amount, orderId, merchantId, gateway, method } = dto;
const { authority } = await this.paymentGatewayService.requestToGateway(
paymentMethod,
method,
amount,
orderId,
merchantId,