From 8e08c1ca6f4564d0a3c87a850dd095fafac1e525 Mon Sep 17 00:00:00 2001 From: quantum-grit Date: Tue, 5 Sep 2023 16:56:26 +0300 Subject: [PATCH 1/3] fixed: vault amount incorrectly increased on updated donation --- apps/api/src/campaign/campaign.service.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/api/src/campaign/campaign.service.ts b/apps/api/src/campaign/campaign.service.ts index 284e51b2e..cdc82ede5 100644 --- a/apps/api/src/campaign/campaign.service.ts +++ b/apps/api/src/campaign/campaign.service.ts @@ -630,7 +630,10 @@ export class CampaignService { }) //if donation is switching to successful, increment the vault amount and send notification - if (newDonationStatus === DonationStatus.succeeded) { + if ( + donation.status != DonationStatus.succeeded && + newDonationStatus === DonationStatus.succeeded + ) { await this.vaultService.incrementVaultAmount( donation.targetVaultId, paymentData.netAmount, @@ -743,8 +746,15 @@ export class CampaignService { async createDonationWish(wish: string, donationId: string, campaignId: string) { const person = await this.prisma.donation.findUnique({ where: { id: donationId } }).person() - await this.prisma.donationWish.create({ - data: { + await this.prisma.donationWish.upsert({ + where: { donationId }, + create: { + message: wish, + donationId, + campaignId, + personId: person?.id, + }, + update: { message: wish, donationId, campaignId, From f71cd804a91898c50a207e5e90bc3c4de4a8880f Mon Sep 17 00:00:00 2001 From: quantum-grit Date: Tue, 5 Sep 2023 16:57:37 +0300 Subject: [PATCH 2/3] renamed function for readability --- apps/api/src/donations/events/stripe-payment.service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/api/src/donations/events/stripe-payment.service.ts b/apps/api/src/donations/events/stripe-payment.service.ts index 1e10046da..6658ea241 100644 --- a/apps/api/src/donations/events/stripe-payment.service.ts +++ b/apps/api/src/donations/events/stripe-payment.service.ts @@ -119,7 +119,7 @@ export class StripePaymentService { ) //updateDonationPayment will mark the campaign as completed if amount is reached - await this.checkForCompletedCampaign(metadata.campaignId) + await this.cancelSubscriptionsIfCompletedCampaign(metadata.campaignId) //and finally save the donation wish if (donationId && metadata?.wish) { @@ -307,11 +307,11 @@ export class StripePaymentService { ) //updateDonationPayment will mark the campaign as completed if amount is reached - await this.checkForCompletedCampaign(metadata.campaignId) + await this.cancelSubscriptionsIfCompletedCampaign(metadata.campaignId) } //if the campaign is finished, we need to stop all active subscriptions - async checkForCompletedCampaign(campaignId: string) { + async cancelSubscriptionsIfCompletedCampaign(campaignId: string) { const updatedCampaign = await this.campaignService.getCampaignById(campaignId) if (updatedCampaign.state === CampaignState.complete) { const recurring = From d1823dd20d9bc95a46084129b3fce62a5e00abcd Mon Sep 17 00:00:00 2001 From: quantum-grit Date: Tue, 5 Sep 2023 16:58:10 +0300 Subject: [PATCH 3/3] fixed prisma exception handler when response is undefined --- .../api/src/prisma/prisma-client-exception.filter.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/api/src/prisma/prisma-client-exception.filter.ts b/apps/api/src/prisma/prisma-client-exception.filter.ts index 9b8e9bf75..228a4faac 100644 --- a/apps/api/src/prisma/prisma-client-exception.filter.ts +++ b/apps/api/src/prisma/prisma-client-exception.filter.ts @@ -67,11 +67,13 @@ export class PrismaClientExceptionFilter extends BaseExceptionFilter { return { property: el, children: [], constraints } }) - response.status(status).json({ - statusCode: status, - message, - error: this.cleanUpException(exception), - }) + if (response) { + response.status(status).json({ + statusCode: status, + message, + error: this.cleanUpException(exception), + }) + } } /**