Skip to content

Commit

Permalink
donations.service: Rename currentDonation to currentPayment in update fn
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Mar 4, 2024
1 parent db91e4f commit 0a7189d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,32 +684,32 @@ export class DonationsService {
try {
// execute the below in prisma transaction
return await this.prisma.$transaction(async (tx) => {
const currentDonation = await tx.payment.findFirst({
const currentPayment = await tx.payment.findFirst({
where: { id },
include: {
donations: {
select: { personId: true, targetVaultId: true },
},
},
})
if (!currentDonation) {
if (!currentPayment) {
throw new NotFoundException(`Update failed. No donation found with ID: ${id}`)
}

if (
currentDonation.status === PaymentStatus.succeeded &&
currentPayment.status === PaymentStatus.succeeded &&
updatePaymentDto.status &&
updatePaymentDto.status !== PaymentStatus.succeeded
) {
throw new BadRequestException('Succeeded donations cannot be updated.')
}

const status = updatePaymentDto.status || currentDonation.status
let donorId = currentDonation.donations[0].personId
const status = updatePaymentDto.status || currentPayment.status
let donorId = currentPayment.donations[0].personId
let billingEmail: string | null = ''
if (
(updatePaymentDto.targetPersonId &&
currentDonation.donations[0].personId !== updatePaymentDto.targetPersonId) ||
currentPayment.donations[0].personId !== updatePaymentDto.targetPersonId) ||
updatePaymentDto.billingEmail
) {
const targetDonor = await tx.person.findFirst({
Expand Down Expand Up @@ -745,19 +745,19 @@ export class DonationsService {
//In case of personId or billingEmail change, take the last updatedAt property to prevent any changes to updatedAt property
updatedAt:
updatePaymentDto.targetPersonId || updatePaymentDto.billingEmail
? currentDonation.updatedAt
? currentPayment.updatedAt
: undefined,
},
})

if (
currentDonation.status !== PaymentStatus.succeeded &&
currentPayment.status !== PaymentStatus.succeeded &&
updatePaymentDto.status === PaymentStatus.succeeded &&
donation.status === PaymentStatus.succeeded
) {
await this.vaultService.incrementVaultAmount(
currentDonation.donations[0].targetVaultId,
currentDonation.amount,
currentPayment.donations[0].targetVaultId,
currentPayment.amount,
tx,
)
}
Expand Down

0 comments on commit 0a7189d

Please sign in to comment.