Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src/donations: Fix stripe refund not working #624

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,7 +24,7 @@
import { CreateSessionDto } from './dto/create-session.dto'
import { UpdatePaymentDto } from './dto/update-payment.dto'

import { DonationBaseDto, ListDonationsDto } from './dto/list-donations.dto'

Check warning on line 27 in apps/api/src/donations/donations.service.ts

View workflow job for this annotation

GitHub Actions / Run API tests

'DonationBaseDto' is defined but never used
import { donationWithPerson } from './queries/donation.validator'
import { CreateStripePaymentDto } from './dto/create-stripe-payment.dto'
import { ImportStatus } from '../bank-transactions-file/dto/bank-transactions-import-status.dto'
Expand Down Expand Up @@ -482,12 +482,12 @@
}

/**
* 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 @@
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
Loading