Skip to content

Commit

Permalink
src/donations: Fix stripe refund not working (#624)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sashko9807 authored Apr 2, 2024
1 parent 3650d27 commit 2703318
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions apps/api/src/donations/donations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,12 @@ export class DonationsService {
}

/**
* Get donation by id
* @param id Donation id
* @returns {Promise<Donation>} Donation
* Get payment by id
* @param id payment id
* @returns {Promise<PaymentWithDonation>} Payment
* @throws NotFoundException if no donation is found
*/
async getDonationById(id: string): Promise<PaymentWithDonation> {
async getPaymentById(id: string): Promise<PaymentWithDonation> {
try {
const donation = await this.prisma.payment.findFirstOrThrow({
where: { id },
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2703318

Please sign in to comment.