diff --git a/src/modules/payments/controllers/payments.controller.ts b/src/modules/payments/controllers/payments.controller.ts index 0b87017..64969fc 100644 --- a/src/modules/payments/controllers/payments.controller.ts +++ b/src/modules/payments/controllers/payments.controller.ts @@ -6,7 +6,7 @@ import { PaymentMethodService } from '../services/payment-method.service'; import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto'; import { UpdatePaymentMethodDto } from '../dto/update-payment-method.dto'; import { VerifyPaymentDto } from '../dto/verify-payment.dto'; -import { RestId } from 'src/common/decorators'; +import { RestId, UserId } from 'src/common/decorators'; import { AuthGuard } from 'src/modules/auth/guards/auth.guard'; @ApiTags('payments') @@ -26,16 +26,13 @@ export class PaymentsController { return this.paymentMethodService.findByRestaurant(restId); } - - - // @UseGuards(AdminAuthGuard) - // @ApiBearerAuth() - // @Get('admin/payments') - // @ApiOperation({ summary: 'Get all payments' }) - // @ApiOkResponse({ description: 'List of all payments' }) - // findAllPayments() { - // return this.paymentsService.findAll(); - // } + @UseGuards(AuthGuard) + @ApiBearerAuth() + @Get('public/payments') + @ApiOperation({ summary: 'Get all the restaurant payments for user' }) + findAllByRestaurant(@UserId() userId: string, @RestId() restId: string) { + return this.paymentsService.findAllByRestaurantId(restId, userId); + } // @UseGuards(AdminAuthGuard) // @ApiBearerAuth() // @Get('admin/payments/:id') diff --git a/src/modules/payments/services/payments.service.ts b/src/modules/payments/services/payments.service.ts index e944101..0f4441a 100644 --- a/src/modules/payments/services/payments.service.ts +++ b/src/modules/payments/services/payments.service.ts @@ -293,9 +293,13 @@ export class PaymentsService { // return `This action updates a #${_id} payment`; // } - // findAll() { - // return this.em.find(Payment, {}); - // } + findAllByRestaurantId(restId: string, userId: string) { + return this.em.find( + Payment, + { order: { restaurant: { id: restId }, user: { id: userId } } }, + { populate: ['order', 'order.paymentMethod'] }, + ); + } // remove(id: number) { // return `This action removes a #${id} payment`;