Skip to content

Commit 8b800c6

Browse files
authored
donations: Add endpoint which would allow to sync donation and payment amount (#611)
1 parent 794b590 commit 8b800c6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

apps/api/src/donations/donations.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ export class DonationsController {
292292
return this.donationsService.update(id, updatePaymentDto)
293293
}
294294

295+
@Patch(':id/sync-with-payment')
296+
@Roles({
297+
roles: [EditFinancialsRequests.role],
298+
mode: RoleMatchingMode.ANY,
299+
})
300+
async syncWithPayment(@Param('id') donationId: string) {
301+
return await this.donationsService.syncDonationAmountWithPayment(donationId)
302+
}
295303
@Post('delete')
296304
@Roles({
297305
roles: [EditFinancialsRequests.role],

apps/api/src/donations/donations.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,4 +918,19 @@ export class DonationsService {
918918
donationExcelTemplate,
919919
)
920920
}
921+
922+
async syncDonationAmountWithPayment(donationId: string) {
923+
await this.prisma.$transaction(async (tx) => {
924+
const payment = await tx.payment.findFirst({
925+
where: { donations: { some: { id: donationId } } },
926+
})
927+
if (!payment) throw new NotFoundException('No payment found for this donation')
928+
return await this.prisma.donation.update({
929+
where: { id: donationId },
930+
data: {
931+
amount: payment.amount,
932+
},
933+
})
934+
})
935+
}
921936
}

0 commit comments

Comments
 (0)