diff --git a/src/modules/orders/orders.controller.ts b/src/modules/orders/orders.controller.ts index 6d766b2..5b249f6 100644 --- a/src/modules/orders/orders.controller.ts +++ b/src/modules/orders/orders.controller.ts @@ -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) diff --git a/src/modules/orders/orders.service.ts b/src/modules/orders/orders.service.ts index 7b554fd..651ec79 100644 --- a/src/modules/orders/orders.service.ts +++ b/src/modules/orders/orders.service.ts @@ -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) { diff --git a/src/modules/payments/controllers/payments.controller.ts b/src/modules/payments/controllers/payments.controller.ts index 36f8c93..0b87017 100644 --- a/src/modules/payments/controllers/payments.controller.ts +++ b/src/modules/payments/controllers/payments.controller.ts @@ -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() diff --git a/src/modules/payments/services/payments.service.ts b/src/modules/payments/services/payments.service.ts index ea56e4a..b00e63e 100644 --- a/src/modules/payments/services/payments.service.ts +++ b/src/modules/payments/services/payments.service.ts @@ -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,