File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,14 @@ export class DonationsController {
292
292
return this . donationsService . update ( id , updatePaymentDto )
293
293
}
294
294
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
+ }
295
303
@Post ( 'delete' )
296
304
@Roles ( {
297
305
roles : [ EditFinancialsRequests . role ] ,
Original file line number Diff line number Diff line change @@ -918,4 +918,19 @@ export class DonationsService {
918
918
donationExcelTemplate ,
919
919
)
920
920
}
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
+ }
921
936
}
You can’t perform that action at this time.
0 commit comments