From 43bb3b1f1b2451966fb6f35310e4d1a9c8fea2c3 Mon Sep 17 00:00:00 2001 From: zlatozar Date: Tue, 8 Aug 2023 19:34:03 +0300 Subject: [PATCH] Refactor successful donation notification handling --- apps/api/src/campaign/campaign.service.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/api/src/campaign/campaign.service.ts b/apps/api/src/campaign/campaign.service.ts index 7e32a9a2e..0b03fbaca 100644 --- a/apps/api/src/campaign/campaign.service.ts +++ b/apps/api/src/campaign/campaign.service.ts @@ -489,7 +489,7 @@ export class CampaignService { select: donationNotificationSelect, }) - if (donation) { + if (donation && newDonationStatus == DonationStatus.succeeded) { donation.status = newDonationStatus this.notificationService.sendNotification('successfulDonation', donation) } @@ -525,8 +525,9 @@ export class CampaignService { }, select: donationNotificationSelect, }) - - this.notificationService.sendNotification('successfulDonation', donation) + if (newDonationStatus === DonationStatus.succeeded) { + this.notificationService.sendNotification('successfulDonation', donation) + } } catch (error) { Logger.error( `Error while creating donation with paymentIntentId: ${paymentData.paymentIntentId} and status: ${newDonationStatus} . Error is: ${error}`, @@ -552,11 +553,12 @@ export class CampaignService { }, select: donationNotificationSelect, }) - - this.notificationService.sendNotification('successfulDonation', { - ...updatedDonation, - person: donation.person, - }) + if (newDonationStatus === DonationStatus.succeeded) { + this.notificationService.sendNotification('successfulDonation', { + ...updatedDonation, + person: donation.person, + }) + } } catch (error) { Logger.error( `Error wile updating donation with paymentIntentId: ${paymentData.paymentIntentId} in database. Error is: ${error}`,