Skip to content

Commit

Permalink
Refactor successful donation notification handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zlati54 committed Aug 8, 2023
1 parent 1dcd8f5 commit 43bb3b1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions apps/api/src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ export class CampaignService {
select: donationNotificationSelect,
})

if (donation) {
if (donation && newDonationStatus == DonationStatus.succeeded) {
donation.status = newDonationStatus
this.notificationService.sendNotification('successfulDonation', donation)
}
Expand Down Expand Up @@ -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}`,
Expand All @@ -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}`,
Expand Down

0 comments on commit 43bb3b1

Please sign in to comment.