From 27033180c40e55bfa381728c4a6e13762118baec Mon Sep 17 00:00:00 2001 From: Aleksandar Petkov Date: Tue, 2 Apr 2024 13:54:58 +0300 Subject: [PATCH] src/donations: Fix stripe refund not working (#624) Appereantly the front-end, calls to not existing endpoint, when trying to retrieve payment by id. - Changed the existing /donation/:id endpoint, to /donation/payment/:id. - Switched endpoint from Public to protected, as the data retrieved from this endpoint is not really meant for public --- apps/api/src/donations/donations.controller.ts | 13 ++++++++----- apps/api/src/donations/donations.service.ts | 10 +++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/api/src/donations/donations.controller.ts b/apps/api/src/donations/donations.controller.ts index 63681360..f73ac80b 100644 --- a/apps/api/src/donations/donations.controller.ts +++ b/apps/api/src/donations/donations.controller.ts @@ -14,7 +14,7 @@ import { forwardRef, } from '@nestjs/common' import { ApiQuery, ApiTags } from '@nestjs/swagger' -import { PaymentStatus } from '@prisma/client' + import { AuthenticatedUser, Public, RoleMatchingMode, Roles } from 'nest-keycloak-connect' import { RealmViewSupporters, @@ -195,10 +195,13 @@ export class DonationsController { ) } - @Get(':id') - @Public() - findOne(@Param('id') id: string) { - return this.donationsService.getDonationById(id) + @Get('payments/:id') + @Roles({ + roles: [RealmViewSupporters.role, ViewSupporters.role], + mode: RoleMatchingMode.ANY, + }) + findOne(@Param('id') paymentId: string) { + return this.donationsService.getPaymentById(paymentId) } @Get('user/:id') diff --git a/apps/api/src/donations/donations.service.ts b/apps/api/src/donations/donations.service.ts index d04a6cfe..407755bb 100644 --- a/apps/api/src/donations/donations.service.ts +++ b/apps/api/src/donations/donations.service.ts @@ -482,12 +482,12 @@ export class DonationsService { } /** - * Get donation by id - * @param id Donation id - * @returns {Promise} Donation + * Get payment by id + * @param id payment id + * @returns {Promise} Payment * @throws NotFoundException if no donation is found */ - async getDonationById(id: string): Promise { + async getPaymentById(id: string): Promise { try { const donation = await this.prisma.payment.findFirstOrThrow({ where: { id }, @@ -788,7 +788,7 @@ export class DonationsService { async invalidate(id: string) { try { await this.prisma.$transaction(async (tx) => { - const donation = await this.getDonationById(id) + const donation = await this.getPaymentById(id) if (donation.status === PaymentStatus.succeeded) { await this.vaultService.decrementVaultAmount(