Skip to content

Commit

Permalink
donations: Add endpoint which would allow to sync donation and paymen…
Browse files Browse the repository at this point in the history
…t amount (#611)
  • Loading branch information
sashko9807 authored Mar 14, 2024
1 parent 794b590 commit 8b800c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/api/src/donations/donations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ export class DonationsController {
return this.donationsService.update(id, updatePaymentDto)
}

@Patch(':id/sync-with-payment')
@Roles({
roles: [EditFinancialsRequests.role],
mode: RoleMatchingMode.ANY,
})
async syncWithPayment(@Param('id') donationId: string) {
return await this.donationsService.syncDonationAmountWithPayment(donationId)
}
@Post('delete')
@Roles({
roles: [EditFinancialsRequests.role],
Expand Down
15 changes: 15 additions & 0 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,4 +918,19 @@ export class DonationsService {
donationExcelTemplate,
)
}

async syncDonationAmountWithPayment(donationId: string) {
await this.prisma.$transaction(async (tx) => {
const payment = await tx.payment.findFirst({
where: { donations: { some: { id: donationId } } },
})
if (!payment) throw new NotFoundException('No payment found for this donation')
return await this.prisma.donation.update({
where: { id: donationId },
data: {
amount: payment.amount,
},
})
})
}
}

0 comments on commit 8b800c6

Please sign in to comment.